fork(1) download
  1. #include <stdio.h>
  2. #include <sys/types.h>
  3. #include <unistd.h>
  4. #define N 3
  5. int main()
  6. {
  7. int i,p;
  8. for(i=0; i<N; i++){
  9. printf("%d %d\n", i, getpid());
  10. if(p=fork()){
  11. printf("Rotto %d\n", p);
  12. break;
  13. }
  14. }
  15. }
Success #stdin #stdout 0s 5308KB
stdin
Standard input is empty
stdout
0 4022842
Rotto 4022845
0 4022842
1 4022845
Rotto 4022846
0 4022842
1 4022845
2 4022846
Rotto 4022847
0 4022842
1 4022845
2 4022846