/* open/read/write/close */
#include <fcntl.h>
+/* Signals handling.. */
+#include <signal.h>
+
/** 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.
/** 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);
/* open/read/write/close */
#include <fcntl.h>
+/* Signals handling.. */
+#include <signal.h>
+
/** 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 grabs data from process1, calculates number of characters in each line
* and pass the value to process3.
fprintf(stderr, "[%s] Init!\n", "process2");
+ /**
+ * 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");
+ }
+
while(1) {
/* Read data from input pipe */
count = read(read_descriptor, buffer, BUFFER_STEP);
/* open/read/write/close */
#include <fcntl.h>
+/* Signals handling.. */
+#include <signal.h>
+
+/**
+ * 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 grabs data (calculated number of characters) from process2 and prints
* grabbed data to the standard output.
/** Stores number of bytes read from input pipe in current iteration */
ssize_t count = 0;
+ fprintf(stderr, "[%s] Init!\n", "process3");
+
+ /**
+ * 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");
+ }
+
/* Reading from process2 */
read_descriptor = open(read_pipe, O_RDONLY);
- fprintf(stderr, "[%s] Init!\n", "process3");
-
while(1) {
/* Read data from input pipe */
count = read(read_descriptor, &buffer, sizeof(int));