Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /******************************************************************
- Welcome to the Operating System examination
- You are editing the '/home/esame/prog.c' file. You cannot remove
- this file, just edit it so as to produce your own program according to
- the specification listed below.
- In the '/home/esame/'directory you can find a Makefile that you can
- use to compile this program to generate an executable named 'prog'
- in the same directory. Typing 'make posix' you will compile for
- Posix, while typing 'make winapi' you will compile for WinAPI just
- depending on the specific technology you selected to implement the
- given specification. Most of the required header files (for either
- Posix or WinAPI compilation) are already included in the head of the
- prog.c file you are editing.
- At the end of the examination, the last saved snapshot of this file
- will be automatically stored by the system and will be then considered
- for the evaluation of your exam. Modifications made to prog.c which are
- not saved by you via the editor will not appear in the stored version
- of the prog.c file.
- In other words, unsaved changes will not be tracked, so please save
- this file when you think you have finished software development.
- You can also modify the Makefile if requesed, since this file will also
- be automatically stored together with your program and will be part
- of the final data to be evaluated for your exam.
- PLEASE BE CAREFUL THAT THE LAST SAVED VERSION OF THE prog.c FILE (and of
- the Makfile) WILL BE AUTOMATICALLY STORED WHEN YOU CLOSE YOUR EXAMINATION
- VIA THE CLOSURE CODE YOU RECEIVED, OR WHEN THE TIME YOU HAVE BEEN GRANTED
- TO DEVELOP YOUR PROGRAM EXPIRES.
- SPECIFICATION TO BE IMPLEMENTED:
- Implementare una programma che riceva in input, tramite argv[], il nome
- di un file F ed N stringhe (con N maggiore o uguale a 1).
- Per ogni stringa S_i ricevuta input dovra' essere attivato un nuovo thread T_i.
- Il main thread dovra' leggere indefinitamente stringhe dallo standard-input
- e dovra' rendere ogni stringa letta disponibile a tutti gli altri N thread.
- Ciascun thread T_i a sua volta, per ogni stringa letta dal main thread, dovra' verificare
- se questa sia contenuta nella stringa S_i ed in caso positivo dovra' scrivere la stringa proveniente
- dallo standard-input su una nuova linea del file F.
- Per ogni thread T_i il programma dovra' tenere traccia del numero di volte
- in cui la stringa S_i e' risultata contenere una qualsiasi stringa letta dal main thread
- dallo standard-input.
- L'applicazione dovra' gestire il segnale SIGINT (o CTRL_C_EVENT nel caso
- WinAPI) in modo tale che quando il processo venga colpito esso dovra'
- riversare su standard-output l'informazione relativa al numero di volte
- in cui ogni thread T_i ha verificato che S_i conteneva una qualsiasi stringa
- letta dal main thread dallo standard-input. Il formato per produrre ssu standard-output
- tale informazione e' lasciato a scelta.
- In caso non vi sia immissione di dati sullo standard input, l'applicazione dovra' utilizzare
- non piu' del 5% della capacita' di lavoro della CPU.
- *****************************************************************/
- #ifdef Posix_compile
- #include <unistd.h>
- #include <errno.h>
- #include <signal.h>
- #include <pthread.h>
- #include <sys/types.h>
- #include <sys/ipc.h>
- #include <sys/mman.h>
- #include <sys/sem.h>
- #include <semaphore.h>
- #include <fcntl.h>
- #else
- #include <windows.h>
- #endif
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- int main(int argc, char** argv){
- return 0;
- }
- prog-B.c
- /******************************************************************
- Welcome to the Operating System examination
- You are editing the '/home/esame/prog.c' file. You cannot remove
- this file, just edit it so as to produce your own program according to
- the specification listed below.
- In the '/home/esame/'directory you can find a Makefile that you can
- use to compile this program to generate an executable named 'prog'
- in the same directory. Typing 'make posix' you will compile for
- Posix, while typing 'make winapi' you will compile for WinAPI just
- depending on the specific technology you selected to implement the
- given specification. Most of the required header files (for either
- Posix or WinAPI compilation) are already included in the head of the
- prog.c file you are editing.
- At the end of the examination, the last saved snapshot of this file
- will be automatically stored by the system and will be then considered
- for the evaluation of your exam. Modifications made to prog.c which are
- not saved by you via the editor will not appear in the stored version
- of the prog.c file.
- In other words, unsaved changes will not be tracked, so please save
- this file when you think you have finished software development.
- You can also modify the Makefile if requesed, since this file will also
- be automatically stored together with your program and will be part
- of the final data to be evaluated for your exam.
- PLEASE BE CAREFUL THAT THE LAST SAVED VERSION OF THE prog.c FILE (and of
- the Makfile) WILL BE AUTOMATICALLY STORED WHEN YOU CLOSE YOUR EXAMINATION
- VIA THE CLOSURE CODE YOU RECEIVED, OR WHEN THE TIME YOU HAVE BEEN GRANTED
- TO DEVELOP YOUR PROGRAM EXPIRES.
- SPECIFICATION TO BE IMPLEMENTED:
- Implementare una programma che riceva in input, tramite argv[],
- N stringhe (con N maggiore o uguale a 1).
- Per ogni stringa S_i ricevuta input dovra' essere attivato un nuovo
- processo figlio P_i. Il processo padre dovra' leggere indefinitamente
- stringhe dallo standard-input e dovra' rendere ogni stringa letta disponibile
- a tutti gli altri N processi figli tramite memoria condivisa.
- Ciascun processo P_i a sua volta, per ogni stringa letta dal processo padre
- dallo standard-input, dovra' verificare se questa sia contenuta nella
- stringa S_i ed in caso positivo dovra' mantenere la stringa originariamente
- proveniente dallo standard-input in memoria.
- L'applicazione dovra' gestire il segnale SIGINT (o CTRL_C_EVENT nel caso
- WinAPI) in modo tale che quando il processo padre venga colpito esso dovra'
- inoltrare lo stesso segnale verso tutti i processi figli. D'altro canto, se
- ad essere colpito e' uno qualsiasi dei processi figli, questo dovra' riversare su
- standard-output le stringhe che attualmente mantiene in memoria.
- In caso non vi sia immissione di dati sullo standard-input, l'applicazione
- dovra' utilizzare non piu' del 5% della capacita' di lavoro della CPU.
- *****************************************************************/
- #ifdef Posix_compile
- #include <unistd.h>
- #include <errno.h>
- #include <signal.h>
- #include <pthread.h>
- #include <sys/types.h>
- #include <sys/ipc.h>
- #include <sys/mman.h>
- #include <sys/sem.h>
- #include <semaphore.h>
- #include <fcntl.h>
- #else
- #include <windows.h>
- #endif
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- int main(int argc, char** argv){
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement