Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h> //puts
- #include <signal.h> //signal, kill
- #include <unistd.h> //read,
- #include <sys/types.h> //kill, getppid
- pid_t cabin;
- static int status = 0; //0 means that button is inactive, 1 - it is activated (or pressed)
- void
- react(int sig);
- void
- press(int sig)
- {
- signal(SIGUSR1, SIG_IGN);
- if (status != 1) {
- status = 1;
- puts("You've called an elevator from street");
- printf("%d\n",cabin);
- sleep(4);
- kill(cabin, SIGUSR1);
- }
- signal(SIGUSR1, press);
- return;
- }
- void
- react(int sig)
- {
- puts("Ground button is set inactive");
- status = 0;
- return;
- }
- void
- sig_int_handl(int sig)
- {
- //signal(SIGINT, sig_int_handl);
- if (status == 0) {
- puts("Button on ground - not pressed");
- }
- if (status == 1) {
- puts("Button on ground is pressed");
- }
- return;
- }
- int
- main(void)
- {
- //signal(SIGFPE, SIG_IGN);
- signal(SIGTERM, SIG_DFL);
- pid_t t;
- read(0, &t, sizeof(pid_t));
- printf("%d BLYA\n", t);
- //pid_t ppid = getppid();
- //kill(ppid, SIGUSR1); //our process indicates that it is ready to work
- signal(SIGUSR1, press); //вызвали лифт с поверхности
- signal(SIGTRAP, react); //ответ от двери
- signal(SIGINT, sig_int_handl);
- while(1){
- pause();
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement