Advertisement
Guest User

Untitled

a guest
Mar 30th, 2020
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.85 KB | None | 0 0
  1. #include <sys/types.h>
  2. #include <sys/wait.h>
  3. #include <stdio.h>
  4. #include <stdlib.h>
  5. #include <fcntl.h>
  6. #include <unistd.h>
  7. #include <dirent.h>
  8.  
  9. /*
  10. Student: Bivolaru Alexandru
  11. Grupa: 30225
  12. */
  13.  
  14. int counter()
  15. {
  16. pid_t current;
  17. int status;
  18. int fd = open("Fisier.txt",O_RDWR);
  19. if(fd == -1)
  20. {
  21. printf("fisierul nu s-a putut deschide!");
  22. exit(1);
  23. }
  24. for(int i = 1; i <= 10; i++)
  25. {
  26. current = fork();
  27. if(current > 0)
  28. {
  29. waitpid(current,&status,0);
  30. char c;
  31. if(write(fd,&c,sizeof(char)) < 0)
  32. {
  33. printf("Nu s-a putut scrie in fisier!");
  34. exit(1);
  35. }
  36. }
  37. }
  38. long procese = lseek(fd,0,SEEK_END);
  39. return procese;
  40. }
  41.  
  42. int main()
  43. {
  44. printf("%d\n",counter());
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement