Answers for "get pid c"

C
1

get pid c

#include <stdio.h>
#include <stdlib.h>
int main()
{
    int pid;
    printf("1) before the forkn");
    pid = fork();
    printf("2) after the forkn");
    if (pid == 0)
    {
        printf("3) i am the child process, my pid is %dn", getpid());
        printf("my parent has the pid %dn", getppid());
        exit(1);
    }
    else
    {
        printf("i am the parent process, my pid is %dn", getpid());
        printf("my parent has the pid %dn", getppid());
        exit(0); //the father of the father is the terminal
    }
}
// THIS ONLY WORKS ON LINUX
Posted by: Guest on November-14-2021

Code answers related to "C"

Browse Popular Code Answers by Language