Advertisement
Guest User

Untitled

a guest
Jul 18th, 2019
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.85 KB | None | 0 0
  1. /******************************************************************
  2. Welcome to the Operating System examination
  3.  
  4. You are editing the '/home/esame/prog.c' file. You cannot remove
  5. this file, just edit it so as to produce your own program according to
  6. the specification listed below.
  7.  
  8. In the '/home/esame/'directory you can find a Makefile that you can
  9. use to compile this program to generate an executable named 'prog'
  10. in the same directory. Typing 'make posix' you will compile for
  11. Posix, while typing 'make winapi' you will compile for WinAPI just
  12. depending on the specific technology you selected to implement the
  13. given specification. Most of the required header files (for either
  14. Posix or WinAPI compilation) are already included in the head of the
  15. prog.c file you are editing.
  16.  
  17. At the end of the examination, the last saved snapshot of this file
  18. will be automatically stored by the system and will be then considered
  19. for the evaluation of your exam. Modifications made to prog.c which are
  20. not saved by you via the editor will not appear in the stored version
  21. of the prog.c file.
  22. In other words, unsaved changes will not be tracked, so please save
  23. this file when you think you have finished software development.
  24. You can also modify the Makefile if requesed, since this file will also
  25. be automatically stored together with your program and will be part
  26. of the final data to be evaluated for your exam.
  27.  
  28. PLEASE BE CAREFUL THAT THE LAST SAVED VERSION OF THE prog.c FILE (and of
  29. the Makfile) WILL BE AUTOMATICALLY STORED WHEN YOU CLOSE YOUR EXAMINATION
  30. VIA THE CLOSURE CODE YOU RECEIVED, OR WHEN THE TIME YOU HAVE BEEN GRANTED
  31. TO DEVELOP YOUR PROGRAM EXPIRES.
  32.  
  33.  
  34. SPECIFICATION TO BE IMPLEMENTED:
  35. Implementare una programma che riceva in input, tramite argv[], il nome
  36. di un file F ed N stringhe (con N maggiore o uguale a 1).
  37. Per ogni stringa S_i ricevuta input dovra' essere attivato un nuovo thread T_i.
  38. Il main thread dovra' leggere indefinitamente stringhe dallo standard-input
  39. e dovra' rendere ogni stringa letta disponibile a tutti gli altri N thread.
  40. Ciascun thread T_i a sua volta, per ogni stringa letta dal main thread, dovra' verificare
  41. se questa sia contenuta nella stringa S_i ed in caso positivo dovra' scrivere la stringa proveniente
  42. dallo standard-input su una nuova linea del file F.
  43. Per ogni thread T_i il programma dovra' tenere traccia del numero di volte
  44. in cui la stringa S_i e' risultata contenere una qualsiasi stringa letta dal main thread
  45. dallo standard-input.
  46.  
  47. L'applicazione dovra' gestire il segnale SIGINT (o CTRL_C_EVENT nel caso
  48. WinAPI) in modo tale che quando il processo venga colpito esso dovra'
  49. riversare su standard-output l'informazione relativa al numero di volte
  50. in cui ogni thread T_i ha verificato che S_i conteneva una qualsiasi stringa
  51. letta dal main thread dallo standard-input. Il formato per produrre ssu standard-output
  52. tale informazione e' lasciato a scelta.
  53.  
  54. In caso non vi sia immissione di dati sullo standard input, l'applicazione dovra' utilizzare
  55. non piu' del 5% della capacita' di lavoro della CPU.
  56.  
  57. *****************************************************************/
  58. #ifdef Posix_compile
  59. #include <unistd.h>
  60. #include <errno.h>
  61. #include <signal.h>
  62. #include <pthread.h>
  63. #include <sys/types.h>
  64. #include <sys/ipc.h>
  65. #include <sys/mman.h>
  66. #include <sys/sem.h>
  67. #include <semaphore.h>
  68. #include <fcntl.h>
  69. #else
  70. #include <windows.h>
  71. #endif
  72.  
  73. #include <stdio.h>
  74. #include <stdlib.h>
  75. #include <string.h>
  76.  
  77.  
  78. int main(int argc, char** argv){
  79.  
  80. return 0;
  81. }
  82.  
  83.  
  84. prog-B.c
  85.  
  86. /******************************************************************
  87. Welcome to the Operating System examination
  88.  
  89. You are editing the '/home/esame/prog.c' file. You cannot remove
  90. this file, just edit it so as to produce your own program according to
  91. the specification listed below.
  92.  
  93. In the '/home/esame/'directory you can find a Makefile that you can
  94. use to compile this program to generate an executable named 'prog'
  95. in the same directory. Typing 'make posix' you will compile for
  96. Posix, while typing 'make winapi' you will compile for WinAPI just
  97. depending on the specific technology you selected to implement the
  98. given specification. Most of the required header files (for either
  99. Posix or WinAPI compilation) are already included in the head of the
  100. prog.c file you are editing.
  101.  
  102. At the end of the examination, the last saved snapshot of this file
  103. will be automatically stored by the system and will be then considered
  104. for the evaluation of your exam. Modifications made to prog.c which are
  105. not saved by you via the editor will not appear in the stored version
  106. of the prog.c file.
  107. In other words, unsaved changes will not be tracked, so please save
  108. this file when you think you have finished software development.
  109. You can also modify the Makefile if requesed, since this file will also
  110. be automatically stored together with your program and will be part
  111. of the final data to be evaluated for your exam.
  112.  
  113. PLEASE BE CAREFUL THAT THE LAST SAVED VERSION OF THE prog.c FILE (and of
  114. the Makfile) WILL BE AUTOMATICALLY STORED WHEN YOU CLOSE YOUR EXAMINATION
  115. VIA THE CLOSURE CODE YOU RECEIVED, OR WHEN THE TIME YOU HAVE BEEN GRANTED
  116. TO DEVELOP YOUR PROGRAM EXPIRES.
  117.  
  118.  
  119. SPECIFICATION TO BE IMPLEMENTED:
  120. Implementare una programma che riceva in input, tramite argv[],
  121. N stringhe (con N maggiore o uguale a 1).
  122. Per ogni stringa S_i ricevuta input dovra' essere attivato un nuovo
  123. processo figlio P_i. Il processo padre dovra' leggere indefinitamente
  124. stringhe dallo standard-input e dovra' rendere ogni stringa letta disponibile
  125. a tutti gli altri N processi figli tramite memoria condivisa.
  126. Ciascun processo P_i a sua volta, per ogni stringa letta dal processo padre
  127. dallo standard-input, dovra' verificare se questa sia contenuta nella
  128. stringa S_i ed in caso positivo dovra' mantenere la stringa originariamente
  129. proveniente dallo standard-input in memoria.
  130.  
  131. L'applicazione dovra' gestire il segnale SIGINT (o CTRL_C_EVENT nel caso
  132. WinAPI) in modo tale che quando il processo padre venga colpito esso dovra'
  133. inoltrare lo stesso segnale verso tutti i processi figli. D'altro canto, se
  134. ad essere colpito e' uno qualsiasi dei processi figli, questo dovra' riversare su
  135. standard-output le stringhe che attualmente mantiene in memoria.
  136.  
  137. In caso non vi sia immissione di dati sullo standard-input, l'applicazione
  138. dovra' utilizzare non piu' del 5% della capacita' di lavoro della CPU.
  139.  
  140. *****************************************************************/
  141. #ifdef Posix_compile
  142. #include <unistd.h>
  143. #include <errno.h>
  144. #include <signal.h>
  145. #include <pthread.h>
  146. #include <sys/types.h>
  147. #include <sys/ipc.h>
  148. #include <sys/mman.h>
  149. #include <sys/sem.h>
  150. #include <semaphore.h>
  151. #include <fcntl.h>
  152. #else
  153. #include <windows.h>
  154. #endif
  155.  
  156. #include <stdio.h>
  157. #include <stdlib.h>
  158. #include <string.h>
  159.  
  160.  
  161. int main(int argc, char** argv){
  162.  
  163. return 0;
  164. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement