fork(116) 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. wait(NULL);
  19. for (i = 0; i < SIZE; i++)
  20. printf("PARENT: %d ",nums[i]); /* LINE Y */
  21. }
  22. puts("");
  23. return 0;
  24. }
Success #stdin #stdout 0s 1832KB
stdin
Standard input is empty
stdout
CHILD: 0 CHILD: -1 CHILD: -4 CHILD: -9 CHILD: -16 
PARENT: 0 PARENT: 1 PARENT: 2 PARENT: 3 PARENT: 4