Advertisement
Guest User

Untitled

a guest
May 27th, 2015
250
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.60 KB | None | 0 0
  1. #include <stdlib.h>
  2. #include <stdio.h>
  3. #include <unistd.h>
  4.  
  5. int
  6. main(int argc, char ** argv) {
  7.  
  8. int noProcs;
  9. int i;
  10. pid_t parent, child;;
  11.  
  12. if (sscanf (argv[1], "%i", &noProcs)!=1)
  13. { printf ("error - not an integer"); }
  14.  
  15. printf("As esu tevas: pid = %d ppid = %d\n", getpid(), getppid());
  16. parent = fork();
  17. if (parent == 0) {
  18. printf("As esu vaikas: pid = %d ppid = %d\n", getpid(), getppid());
  19. for (i = 0; i < noProcs; ++i) {
  20. child = fork();
  21. if (child == 0) {
  22. printf("As esu anukas: pid = %d ppid = %d\n", getpid(), getppid());
  23. exit(0);
  24. }
  25. }
  26. exit(0);
  27. }
  28.  
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement