6 /* open/read/write/close */
9 /* Signals handling.. */
12 /** Named pipe used to communicate with process2 */
13 char * read_pipe = "/tmp/process2pipe";
15 /** Descriptor of input pipe */
19 * Handler for signals.
21 void sig_handler(int signo)
23 if (signo == SIGUSR1) {
24 fprintf(stderr, "[%s] Received SIGUSR1!\n", "process3");
26 else if (signo == SIGTERM) {
27 fprintf(stderr, "[%s] Received SIGTERM!\n", "process3");
28 fprintf(stderr, "[%s] > Releasing resources\n", "process3");
29 close(read_descriptor);
32 else if (signo == SIGINT) {
33 fprintf(stderr, "[%s] Received SIGINT!\n", "process3");
34 fprintf(stderr, "[%s] > Closing pipe\n", "process2");
35 close(read_descriptor);
37 else if (signo == SIGCONT) {
38 fprintf(stderr, "[%s] Received SIGCONT!\n", "process3");
39 fprintf(stderr, "[%s] > Opening pipe\n", "process2");
40 read_descriptor = open(read_pipe, O_RDONLY);
45 * Program grabs data (calculated number of characters) from process2 and prints
46 * grabbed data to the standard output.
49 /** Buffer used for storing data from input pipe */
52 /** Stores number of bytes read from input pipe in current iteration */
55 fprintf(stderr, "[%s] Init!\n", "process3");
58 * Register signals handled by process
60 if (signal(SIGUSR1, sig_handler) == SIG_ERR) {
61 fprintf(stderr, "can't catch SIGUSR1\n");
63 if (signal(SIGTERM, sig_handler) == SIG_ERR) {
64 fprintf(stderr, "can't catch SIGTERM\n");
66 if (signal(SIGINT, sig_handler) == SIG_ERR) {
67 fprintf(stderr, "can't catch SIGINT\n");
69 if (signal(SIGCONT, sig_handler) == SIG_ERR) {
70 fprintf(stderr, "can't catch SIGCONT\n");
73 /* Reading from process2 */
74 read_descriptor = open(read_pipe, O_RDONLY);
77 /* Read data from input pipe */
78 count = read(read_descriptor, &buffer, sizeof(int));
80 fprintf(stderr, "[%s] Fetched: %d bytes\n", "process3", count);
83 fprintf(stderr, "[%s] Process2 send: %d\n", "process3", buffer);
90 /* Release resources in normal program flow exit. */
91 close(read_descriptor);