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);
36 else if (signo == SIGCONT) {
37 fprintf(stderr, "[%s] > Opening pipe\n", "process3");
38 read_descriptor = open(read_pipe, O_RDONLY);
43 * Program grabs data (calculated number of characters) from process2 and prints
44 * grabbed data to the standard output.
47 /** Buffer used for storing data from input pipe */
50 /** Stores number of bytes read from input pipe in current iteration */
53 fprintf(stderr, "[%s] Init!\n", "process3");
56 * Register signals handled by process
58 if (signal(SIGUSR1, sig_handler) == SIG_ERR) {
59 fprintf(stderr, "can't catch SIGUSR1\n");
61 if (signal(SIGTERM, sig_handler) == SIG_ERR) {
62 fprintf(stderr, "can't catch SIGTERM\n");
64 if (signal(SIGTSTP, sig_handler) == SIG_ERR) {
65 fprintf(stderr, "can't catch SIGTSTP\n");
67 if (signal(SIGCONT, sig_handler) == SIG_ERR) {
68 fprintf(stderr, "can't catch SIGCONT\n");
71 /* Reading from process2 */
72 read_descriptor = open(read_pipe, O_RDONLY);
75 /* Read data from input pipe */
76 count = read(read_descriptor, &buffer, sizeof(int));
78 fprintf(stderr, "[%s] Fetched: %d bytes\n", "process3", count);
81 fprintf(stderr, "[%s] Process2 send: %d\n", "process3", buffer);
88 /* Release resources in normal program flow exit. */
89 close(read_descriptor);