We Recommend

C++ The Core Language C++ The Core Language
C++: The Core Language is for C programmers transitioning to C++. It's designed to get readers up to speed quickly by covering an essential subset of the language. The subset consists of features without which it's just not C++, and a handful of others that make it a reasonably useful language.


Posted By

Feb30th1712 on 01/13/08


Tagged

c demo fork pidt


Versions (?)


racing condition


Published in: C++ 


URL: http://src.wtgstudio.com/?EoG1Ah

  1. #include <stdio.h>
  2.  
  3. void printn(int n, pid_t pid)
  4. {
  5. int c;
  6. for (c = 0; c < n; c++)
  7. if (pid)
  8. printf("parent: %d\n", c);
  9. else
  10. printf("child: %2d\n", c);
  11. }
  12.  
  13. int main(void)
  14. {
  15. pid_t pid;
  16. pid = fork();
  17. printn(5, pid);
  18. return 0;
  19. }

Report this snippet 

You need to login to post a comment.