To use fork() to get the Parent and Child Process ID > C Program
Operating Systems
Program using fork() to get the Parent and Child Process ID
#include<stdio.h>
#include<string.h>
#include<fcntl.h>
#include<sys/stat.h>
#include<sys/types.h>
int main(){
int pid, p1, c;
p1=open("data",O_RDONLY);
pid=fork();
c = getpid();
if(pid<0)
printf("Error");
else if(pid>=0)
printf( "The process id is: %d\n", c);
return 0;
}
Output:
The process id is: 5052
The process id is: 5051
Comments
Post a Comment