Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <sys/types.h>
- #include <unistd.h>
- void main()
- {
- pid_t pid;
- printf("Welcome");
- printf("Welcome");
- printf("\nMy process id:%d ParentProcessId:%d",getpid(),getppid());
- //printf("Welcome");
- printf("\n");
- pid=fork();
- if (pid > 0)
- {
- sleep(20);
- printf("\nI am parent");
- }
- else if (pid==0){
- printf("\nI am the child");
- printf("My process id:%d ParentProcessId:%d",getpid(),getppid());
- sleep(40);
- }
- else if(pid==-1)
- perror("\nfork");
- printf("\n");
- exit(0);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement