📜  获取 pid - C 编程语言代码示例

📅  最后修改于: 2022-03-11 15:04:39.404000             🧑  作者: Mango

代码示例1
#include 
#include 
int main()
{
    int pid;
    printf("1) before the fork\n");
    pid = fork();
    printf("2) after the fork\n");
    if (pid == 0)
    {
        printf("3) i am the child process, my pid is %d\n", getpid());
        printf("my parent has the pid %d\n", getppid());
        exit(1);
    }
    else
    {
        printf("i am the parent process, my pid is %d\n", getpid());
        printf("my parent has the pid %d\n", getppid());
        exit(0); //the father of the father is the terminal
    }
}
// THIS ONLY WORKS ON LINUX