Unix System Calls - fork, getpid, getppid

// Unix system calls
// fork, getpid, getppid

#include<stdio.h>
#include<string.h>
#include<sys/types.h>
#include<unistd.h>

void main()
{
          pid_t pid;
          pid=fork();
         
          if(pid == -1)
                   printf("\n Error in creating process ");
          else if(pid == 0)
          {
                   printf("\nExecuting in child process");
                   printf("\n child process pid=%d ", getpid());
                   printf("\n parent process pid=%d ", getppid());
          }
          else
                   printf("\nExecuting in parent process, pid=%d \n", getppid());
}

No comments:

Post a Comment

Don't be a silent reader...
Leave your comments...

Anu