Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <signal.h>
- #include <unistd.h>
- #include <string.h>
- #include <stdlib.h>
- #include <semaphore.h>
- #include <fcntl.h>
- #include <sys/stat.h>
- int running = 1;
- void sig_handler(int signum)
- {
- running = 0;
- }
- int main(int argc, char** argv)
- {
- struct sigaction act;
- memset(&act, 0, sizeof(struct sigaction));
- act.sa_handler = sig_handler;
- if (sigaction(SIGTERM, &act, NULL) == -1)
- {
- fprintf(stdout, "Sigaction failed\n");
- exit(EXIT_FAILURE);
- }
- sem_t* sem = sem_open("semaphore", 0);
- if (sem == SEM_FAILED)
- {
- fprintf(stderr, "Can't open a semaphore\n");
- exit(EXIT_FAILURE);
- }
- while (running)
- {
- sem_wait(sem);
- fprintf(stdout, "%s\n", argv[1]);
- sem_post(sem);
- }
- sem_close(sem);
- exit(EXIT_SUCCESS);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement