diff options
author | Franciszek Malinka <franciszek.malinka@gmail.com> | 2021-11-13 17:32:03 +0100 |
---|---|---|
committer | Franciszek Malinka <franciszek.malinka@gmail.com> | 2021-11-13 17:32:03 +0100 |
commit | ff0ac5bf2b3069200d2bb5a56bc3eef0b4bcb44a (patch) | |
tree | 6778fd6eb8fb48cff51564d4110ed3bd168a3b2e /semestr-5/so/lista2/signals.c | |
parent | fa505e1e8d7f990d608144ccd97e9f960c6b8b57 (diff) |
update
Diffstat (limited to 'semestr-5/so/lista2/signals.c')
-rw-r--r-- | semestr-5/so/lista2/signals.c | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/semestr-5/so/lista2/signals.c b/semestr-5/so/lista2/signals.c new file mode 100644 index 0000000..a7593bc --- /dev/null +++ b/semestr-5/so/lista2/signals.c @@ -0,0 +1,30 @@ +#include <signal.h> +#include <stdio.h> +#include <unistd.h> +#include <string.h> +#include <sys/wait.h> +#include <stdlib.h> +#include <errno.h> + +void sig_handler(int signum) { + char text[100]; + sprintf(text, "[%d] Hello, I'm a signal handler :)\n", getpid()); + write(STDOUT_FILENO, text, strlen(text)); +} + +int main() { + signal(SIGUSR1, sig_handler); + printf("Parent: [%d]\n", getpid()); + fflush(stdout); + if (fork() == 0) { + printf("Child: [%d]\n", getpid()); + // while(1) {} + if (execl("./echo-my", "echo-my", NULL) < 0) { + fprintf(stderr, "Exec error: %s\n", strerror(errno)); + exit(0); + } + } + + int result; + wait(&result); +} |