fork download
  1. #include <sys/types.h>
  2. #include <stdio.h>
  3. #include <unistd.h>
  4. #define SIZE 5
  5. int nums[SIZE] = {0,1,2,3,4};
  6. int main()
  7. {
  8. int i;
  9. pid_t pid;
  10. pid = fork();
  11. if (pid == 0) {
  12. for (i = 0; i < SIZE; i++) {
  13. nums[i] += i;
  14. printf("CHILD: %d ",nums[i]); /* LINE X */
  15. }
  16. }
  17. else if (pid > 0) {
  18. for (i = 0; i < SIZE; i++)
  19. printf("PARENT: %d ",nums[i]); /* LINE Y */
  20. }
  21. puts("");
  22. return 0;
  23. }
Success #stdin #stdout 0.01s 5288KB
stdin
Standard input is empty
stdout
PARENT: 0 PARENT: 1 PARENT: 2 PARENT: 3 PARENT: 4