Advertisement
Guest User

Untitled

a guest
Aug 19th, 2018
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.52 KB | None | 0 0
  1. #include <sys/types.h>
  2. #include <stdio.h>
  3. #include <unistd.h>
  4. int main(){
  5. pid_t pid, pid1;
  6. /* fork a child process */
  7. pid = fork();
  8. if (pid < 0) { /* error occurred */
  9. fprintf(stderr, "Fork Failed");
  10. return 1;
  11. }
  12. else if (pid == 0) { /* child process */
  13. pid1 = getpid();
  14. printf("child: pid = %d\n",pid); /* A */
  15. printf("child: pid1 = %d\n",pid1); /* B */
  16. }
  17. else { /* parent process */
  18. pid1 = getpid();
  19. printf("parent: pid = %d\n",pid); /* C */
  20. printf("parent: pid1 = %d\n",pid1); /* D */
  21. wait(NULL);
  22. }
  23. return 0;
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement