3 /* open/read/write/close */
6 /* Signals handling.. */
10 * Handler for signals.
12 void sig_handler(int signo)
14 if (signo == SIGUSR1) {
15 fprintf(stderr, "[%s] SIGUSR1!\n", "process1");
17 else if (signo == SIGUSR2) {
18 fprintf(stderr, "[%s] SIGUSR2!\n", "process1");
20 else if (signo == SIGINT) {
21 fprintf(stderr, "[%s] SIGINT!\n", "process1");
23 else if (signo == SIGCONT) {
24 fprintf(stderr, "[%s] SIGCONT!\n", "process1");
29 * Program grabs data (calculated number of characters) from process2 and prints
30 * grabbed data to the standard output.
33 /** Named pipe used to communicate with process2 */
34 char * read_pipe = "/tmp/process2pipe";
36 /** Descriptor of input pipe */
39 /** Buffer used for storing data from input pipe */
42 /** Stores number of bytes read from input pipe in current iteration */
45 fprintf(stderr, "[%s] Init!\n", "process3");
48 * Register signals handled by process
50 if (signal(SIGUSR1, sig_handler) == SIG_ERR) {
51 fprintf(stderr, "can't catch SIGUSR1\n");
53 if (signal(SIGUSR2, sig_handler) == SIG_ERR) {
54 fprintf(stderr, "can't catch SIGUSR2\n");
56 if (signal(SIGINT, sig_handler) == SIG_ERR) {
57 fprintf(stderr, "can't catch SIGINT\n");
59 if (signal(SIGCONT, sig_handler) == SIG_ERR) {
60 fprintf(stderr, "can't catch SIGCONT\n");
63 /* Reading from process2 */
64 read_descriptor = open(read_pipe, O_RDONLY);
67 /* Read data from input pipe */
68 count = read(read_descriptor, &buffer, sizeof(int));
70 fprintf(stderr, "[%s] Fetched: %d bytes\n", "process3", count);
73 fprintf(stderr, "[%s] Process2 send: %d\n", "process3", buffer);
80 close(read_descriptor);