2

this is the part of the code for creating child process

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

main()
{
  pid_t pid;

pid_t was declared as the variable of pid.But values are same like integers.

  int x = 5;
  pid = fork();

fork() is the function which create child process.

  x++;

  if(pid<0)
  {
    printf("process creation error");
    exit(-1);
  }
  else if(pid==0)
  {
    printf("Child Process");
    printf("\nChild Process ID is %d",getpid());
x++;
    printf("\nValue of X is %d",x);  
    printf("\nProcess id of parent is %d",getppid()); 
  }
Rajitha Perera
  • 1,581
  • 5
  • 26
  • 42

1 Answers1

1

The type of the variable pid is pid_t. How pid_t itself is defined is dependant on the operating system. In Linux it's defined like this:

typedef __pid_t pid_t;

and __pid_t is eventually defined as an int. See GCC declarations: typedef __pid_t pid_t?

Community
  • 1
  • 1
abligh
  • 24,573
  • 4
  • 47
  • 84