fork download
  1. #include <sys/types.h>
  2. #include <stdio.h>
  3. #include <unistd.h>
  4. int value = 5;
  5. int main()
  6. {
  7. pid_t pid;
  8. pid = fork();
  9. printf("j");
  10. if (pid == 0) { /* child process */
  11. printf("j");
  12. value += 15;
  13. execlp("/bin/ls", "ls", NULL);
  14. printf("j");
  15. return 0;
  16. }
  17. else if (pid > 0) { /* parent process */
  18. wait(NULL);
  19. printf("PARENT: value = %d",value); /* LINE A */
  20. return 0;
  21. }
  22. }
  23.  
Success #stdin #stdout 0s 5308KB
stdin
Standard input is empty
stdout
prog
jPARENT: value = 5