fork download
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <sys/types.h>
  4. #include <unistd.h>
  5.  
  6. int main(void)
  7. {
  8. int pid,x=2;
  9. if (0 == (pid =fork())) {
  10. fork();
  11. pid=fork();
  12. if (pid==0) {
  13. x--;
  14. }
  15. }
  16. else{
  17. printf("aki\n");
  18. execl("bin/date", "date",0);
  19. x=x+2;
  20. }
  21.  
  22. printf("pid=%d, x=%d\n", pid,x);
  23. exit(0);
  24. }
Success #stdin #stdout 0s 4476KB
stdin
Standard input is empty
stdout
aki
pid=25659, x=4
pid=25661, x=2
pid=0, x=1
pid=25662, x=2