fork(1) download
  1. #include<stdio.h>
  2. #include<stdlib.h>
  3. #include<unistd.h>
  4. int level=1;
  5. int n;
  6. void create()
  7. {
  8. if(level==n)
  9. {
  10. exit(0);
  11. }
  12. printf("current:%d ",getpid());
  13. printf("Parent:%d ",getppid());
  14. if(fork()==0)
  15. {
  16. level++;
  17. printf("Left child:%d ",getpid());
  18. create();
  19. }
  20. if(fork()==0)
  21. {
  22. level++;
  23. printf("Right child:%d ",getpid());
  24. cout<<"\n";
  25. create();
  26. }
  27. exit(0);
  28. }
  29. int main()
  30. {
  31. scanf("%d",&n);
  32. create();
  33. return 0;
  34. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.c: In function ‘create’:
prog.c:24:6: error: ‘cout’ undeclared (first use in this function)
      cout<<"\n";
      ^~~~
prog.c:24:6: note: each undeclared identifier is reported only once for each function it appears in
stdout
Standard output is empty