X-Git-Url: https://git.dlugolecki.net.pl/?a=blobdiff_plain;f=src%2Fprocess1.c;h=b5004830f5c9c43e4aebc60df07a0cf1828e83ea;hb=c0975e5a6af7b478563193dac7c3484b4430d3a3;hp=d514b03e38daa000c379cc21e9c43212576eb2c6;hpb=aaee22da13ed0c8d7b85f22c58ff31a7fc346f25;p=wsti_so.git diff --git a/src/process1.c b/src/process1.c index d514b03..b500483 100644 --- a/src/process1.c +++ b/src/process1.c @@ -5,9 +5,31 @@ /* open/read/write/close */ #include +/* Signals handling.. */ +#include + /** If buffer is too small to hold entire string, it is incremented by this value */ #define BUFFER_STEP 16 +/** + * Handler for signals. + */ +void sig_handler(int signo) +{ + if (signo == SIGUSR1) { + fprintf(stderr, "[%s] SIGUSR1!\n", "process1"); + } + else if (signo == SIGUSR2) { + fprintf(stderr, "[%s] SIGUSR2!\n", "process1"); + } + else if (signo == SIGINT) { + fprintf(stderr, "[%s] SIGINT!\n", "process1"); + } + else if (signo == SIGCONT) { + fprintf(stderr, "[%s] SIGCONT!\n", "process1"); + } +} + /** * Program reads entire lines of text from the standard input and pass them * to the process2 using created pipe. @@ -37,12 +59,28 @@ int main(void) { /** File descriptor of pipe */ int file_descriptor; + fprintf(stderr, "[%s] Init!\n", "process1"); + + /** + * Register signals handled by process + */ + if (signal(SIGUSR1, sig_handler) == SIG_ERR) { + fprintf(stderr, "can't catch SIGUSR1\n"); + } + if (signal(SIGUSR2, sig_handler) == SIG_ERR) { + fprintf(stderr, "can't catch SIGUSR2\n"); + } + if (signal(SIGINT, sig_handler) == SIG_ERR) { + fprintf(stderr, "can't catch SIGINT\n"); + } + if (signal(SIGCONT, sig_handler) == SIG_ERR) { + fprintf(stderr, "can't catch SIGCONT\n"); + } + mkfifo(write_pipe, 0666); file_descriptor = open(write_pipe, O_WRONLY); - fprintf(stderr, "[%s] Init!\n", "process1"); - do { c = fgetc(stdin);