Friday 8 May 2015

Getpid()UNIX System Call

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

int main ()
{
  pid_t child_pid;
  printf("the main program process ID is %d\n", (int) getpid ());
  child_pid = fork ();
  if (child_pid != 0) {
    printf("this is the parent process, with id %d\n", (int) getpid ());
    printf("the child’s process ID is %d\n", (int) child_pid);
  }
  else
    printf ("this is the child process, with id %d\n", (int) getpid ());
  return 0;

}

output

 [telnet23@linux ~]$ ./a.out

the main program process ID is 3045
this is the child process,with id 3046
this is the parent process,with id 3045
 the child`s process ID 3046

No comments:

Post a Comment