Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* basic signals, UNIX-native */
- /* pointer arithmetics:
- *
- * push(pointer, v) INDICATES *(pointer++) = v
- * pop(pointer) INDICATES *(--pointer)
- * (*++v)[0] INDICATES (**++v)
- * INDICATES first char in v
- * INDICATES name of string/vector v
- * likewise, *v[0] INDICATES **v
- * and *v[n] INDICATES **(v + n)
- * returntype (*funct)(args) INDICATES a function funct with arguments args which returns...
- * char **argv INDICATES pointer to char pointer
- * int(*v)[len] INDICATES pointer "v" to a vector of "len" int elements
- * int *v[len] INDICATES vector "v" of "len" pointers to int elements
- * void *funct() INDICATES function "funct" that returns a pointer-to-void
- * void (*funct)() INDICATES pointer to a function "funct" that returns void
- *
- */
- /* useful characters: [] # */
- # include <stdio.h>
- # include <stdlib.h> // for exit
- # include <signal.h>
- # include <sys/shm.h> // for shmdet
- # include <sys/sem.h>
- # include <fcntl.h> // for O_RDWR
- # define BUFFER 256
- # define exception(x) { puts(x); exit(1); }
- void timeout();
- char c; // input char
- int main(int argc, char * argv[])
- {
- /* ALARM example; NOTE: DOES NOT STOP */
- alarm(2); // 2t left before alarm
- signal(SIGALRM, timeout);
- printf("Alarm signal sent\n");
- // while(1) read(0, &c, 1); // reads chars from input
- /* KILL example */
- int pid; // ID of the process to be killed
- printf("Enter server PID: ");
- scanf("%d", &pid);
- kill(pid, SIGTERM);
- }
- /* waits on timeout, then signals */
- void timeout()
- {
- printf("Wake up call\n");
- signal(SIGALRM, timeout); // sends timeout; NOTE: the wakeup executes at regular intervals until the PID is entered, possibly due to recursion?
- alarm(2);
- }
- /* samples at pgs. 63-64 with server-client model */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement