Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <string.h>
- #include <signal.h>
- #include <unistd.h>
- #include <stdlib.h>
- #define MAX_LENGTH 10
- char *buf[MAX_LENGTH];
- static void sigact_handler (int sig, siginfo_t *siginfo, void *context)
- {
- read(0, buf, MAX_LENGTH);
- // printf("Read\n %d");
- write(1, buf, MAX_LENGTH);
- // printf("Written\n\n");
- printf("pid: %ld\nuid: %ld\n\n", (long) siginfo->si_pid, (long) siginfo->si_uid);
- }
- int main (void)
- {
- alarm(10);
- printf("Set alarm.\nEnter a string:\n");
- struct sigaction mysigact;
- // set handler
- mysigact.sa_sigaction = &sigact_handler;
- // says do not use sa_handler field, use the above sa_sigaction field
- // sa_sigaction takes more arguments
- mysigact.sa_flags = SA_RESTART; // switching between SA_SIGINFO and SA_RESTART
- if (sigaction (SIGALRM, &mysigact, NULL) < 0)
- {
- perror("sigalrm");
- return 1;
- }
- while(1) sleep(10);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement