Advertisement
Guest User

Untitled

a guest
Oct 22nd, 2017
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.48 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <unistd.h>
  4. #include <errno.h>
  5. #include <string.h>
  6. #include <signal.h>
  7. #include <sys/types.h>
  8. #include <sys/stat.h>
  9. #include <fcntl.h>
  10. #include <sys/wait.h>
  11. #include <time.h>
  12.  
  13. #define LEN 10000
  14.  
  15. // 1 gig is 256 million ints
  16. // 1 int 4 bytes
  17. int main()
  18. {
  19.  
  20. int data[LEN];
  21. srand(time(NULL));
  22. for (int i = 0; i < LEN; i++)
  23. {
  24. // should only be called once
  25. data[i] = rand() % (10 + 1 - 0) + 0;
  26. //printf("generated: %ld",data[i]);
  27. }
  28. printf("int arr created\n");
  29.  
  30. int childpid = fork();
  31. long int test = 0;
  32. if (childpid == 0) {
  33. int roura2 = open("/tmp/trubka", O_WRONLY | O_NONBLOCK);
  34. printf("Trubka otevrena PRO zapis %d\n", roura2);
  35.  
  36. for (long int i = 0; i < 250; i++) {
  37.  
  38. for (long j= 0; j < LEN+1; j++)
  39. {
  40. test += data[j];
  41. printf("i: %d, TEST: %ld\n",j, test);
  42. }
  43. printf("DEBUG");
  44. printf("i: %ld",i);
  45. int ret = write(roura2, data, sizeof(data));
  46.  
  47.  
  48. }
  49. printf("TEST END: %ld", test);
  50.  
  51. }
  52. else {
  53. int roura = open("/tmp/trubka", O_RDONLY | O_NONBLOCK);
  54. printf("Trubka otevrena PRO CTENI %d\n", roura);
  55.  
  56. for (int i = 0; i < 2500000; i++) {
  57.  
  58.  
  59. int ret2 = read(roura, data, sizeof(data));
  60.  
  61.  
  62. }
  63. }
  64.  
  65. /* remove the FIFO */
  66. //close(roura);
  67. printf("end");
  68. return 0;
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement