Guest User

Untitled

a guest
May 26th, 2018
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.53 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <unistd.h>
  3. #include <sys/wait.h>
  4.  
  5.  
  6. int main( int argc, char *argv[] ){
  7.  
  8.  
  9. FILE *fptr;
  10. pid_t pid;
  11.  
  12. fptr = fopen("Shared File.txt", "a");
  13. pid = fork();
  14.  
  15. if( pid > 0 ){ // parent process
  16.  
  17. int counter = 0;
  18.  
  19. while( counter < 10 ){
  20. fprintf(fptr, "a");
  21. ++counter;
  22. }
  23. wait(NULL);
  24. }
  25. else{
  26.  
  27. int counter = 0;
  28.  
  29. while( counter < 5 ){
  30. fprintf(fptr, "b");
  31. ++counter;
  32. }
  33. }
  34.  
  35. return 0;
  36. }
Add Comment
Please, Sign In to add comment