people. For a academic exercise i have to implement a program in c for nix platform which is to synchronize multiple processes through signal handling, using only signal,pause,kill and fork basic functions.
I searched google and have not found any clear example: I hope the wisdom of one of you will light my way.
Thanks!
people. For a academic exercise i have to implement a program in c for
Share
pausedoesn’t return until a signal is received. The basic design is thus:forkto create the necessary workersSIGINTin each worker. The handler sets a flag meaning the process should exit after finishing it’s current job.pauses. Repeat unlessSIGINTis received (test before & afterpause).SIGCONTThis doesn’t quite include synchronized access to shared data. To do that, you could add an additional rule:
pauseOf course, this rather defeats the purpose of concurrent programming.
Since most system calls are interrupted by signals (causing them to return -1, with
errnoset toEINTR), you’ll have to handle this contingency, repeating each affected system call until it’s successful. For example: