fork(1) 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. if (pid == 0) { /* child process */
  10. printf("j");
  11. value += 15;
  12. execlp("/bin/ls", "ls", NULL);
  13. printf("j");
  14. return 0;
  15. }
  16. else if (pid > 0) { /* parent process */
  17. wait(NULL);
  18. printf("PARENT: value = %d",value); /* LINE A */
  19. return 0;
  20. }
  21. }
  22.  
Success #stdin #stdout 0.01s 5304KB
stdin
Standard input is empty
stdout
prog
PARENT: value = 5