/* 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);