C language to obtain the process identification code of the correlation function

  • 2020-04-02 03:18:37
  • OfStack

C language getpid() function: get the process identification code
The header file:


#include <unistd.h>

Definition function:


pid_t getpid(void);

Getpid () is used to obtain the process identification code of the current process. Many programs use this value to create temporary files to avoid the problems caused by the same temporary files.

Return value: the process identifier of the current process

sample


#include <unistd.h>
main()
{
 printf("pid=%dn", getpid());
}

Perform:


pid=1494 

C getppid() function: gets the process identifier of the parent process
The header file:


#include <unistd.h>

Definition function:


pid_t getppid(void);

Getppid () is used to get the identity of the parent process of the current process.

Return value: the parent process identifier of the current process.

sample


#include <unistd.h>
main()
{
 printf("My parent 'pid =%dn", getppid());
}

Perform:


My parent pid =463



Related articles: