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 fprintf(stderr, "[%s] Received %s!\n", "process3", strsignal(signo));
24 if (signo == SIGUSR1) {
26 else if (signo == SIGTERM) {
27 fprintf(stderr, "[%s] > Releasing resources\n", "process3");
28 close(read_descriptor);
31 else if (signo == SIGTSTP) {
32 fprintf(stderr, "[%s] > Closing pipe\n", "process3");
33 close(read_descriptor);
35 else if (signo == SIGCONT) {
36 fprintf(stderr, "[%s] > Opening pipe\n", "process3");
37 read_descriptor = open(read_pipe, O_RDONLY);
42 * Program grabs data (calculated number of characters) from process2 and prints
43 * grabbed data to the standard output.
46 /** Buffer used for storing data from input pipe */
49 /** Stores number of bytes read from input pipe in current iteration */
52 fprintf(stderr, "[%s] Init!\n", "process3");
55 * Register signals handled by process
57 if (signal(SIGUSR1, sig_handler) == SIG_ERR) {
58 fprintf(stderr, "can't catch SIGUSR1\n");
60 if (signal(SIGTERM, sig_handler) == SIG_ERR) {
61 fprintf(stderr, "can't catch SIGTERM\n");
63 if (signal(SIGTSTP, sig_handler) == SIG_ERR) {
64 fprintf(stderr, "can't catch SIGTSTP\n");
66 if (signal(SIGCONT, sig_handler) == SIG_ERR) {
67 fprintf(stderr, "can't catch SIGCONT\n");
70 /* Reading from process2 */
71 read_descriptor = open(read_pipe, O_RDONLY);
74 /* Read data from input pipe */
75 count = read(read_descriptor, &buffer, sizeof(int));
77 fprintf(stderr, "[%s] Fetched: %d bytes\n", "process3", count);
80 fprintf(stderr, "[%s] Process2 send: %d\n", "process3", buffer);
87 /* Release resources in normal program flow exit. */
88 close(read_descriptor);