Advertisement
Guest User

Untitled

a guest
Jan 16th, 2019
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.77 KB | None | 0 0
  1. #include <sys/mman.h>
  2. #include <sys/types.h>
  3. #include <sys/stat.h>
  4. #include <sys/wait.h>
  5. #include <sys/file.h>
  6. #include <fcntl.h>
  7. #include <stdio.h>
  8. #include <unistd.h>
  9.  
  10.  
  11. int main()
  12. {
  13. int descriptor = creat("tekst2.txt",0600);
  14.  
  15. pid_t pid;
  16. flock(descriptor,LOCK_SH );
  17. pid = fork();
  18.  
  19. if(pid == 0)
  20. {
  21.  
  22. char string_2[] = "POTOMNY PISZE\n";
  23. sleep(3);
  24. lseek(descriptor,0,SEEK_SET);
  25. write(descriptor,(void *)string_2,sizeof(string_2)-1);
  26.  
  27. _exit(0);
  28. }
  29. else
  30. {
  31. char string_1[] = "RODZIC PISZE\n";
  32. lseek(descriptor,0,SEEK_SET);
  33. write(descriptor,(void*)string_1,sizeof(string_1)-1);
  34. }
  35.  
  36. close(descriptor);
  37.  
  38. return 0;
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement