-
Notifications
You must be signed in to change notification settings - Fork 0
/
sample2.c
41 lines (38 loc) · 1.1 KB
/
sample2.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#include <stdio.h>
#include <sys/types.h>
#include <signal.h>
#include <sys/ipc.h>
#include <sys/shm.h>
void main(void)
{
pid_t pid;
key_t MyKey;
int ShmID;
pid_t *ShmPTR;
char line[100], c;
int i;
MyKey = ftok(".", 's');
ShmID = shmget(MyKey, sizeof(pid_t), 0666);
ShmPTR = (pid_t *) shmat(ShmID, NULL, 0);
pid = *ShmPTR;
shmdt(ShmPTR);
while (1) {
printf("Want to interrupt the other guy or kill it (i or k)? ");
gets(line);
for (i = 0; !(isalpha(line[i])); i++)
;
c = line[i];
if (c == 'i' || c == 'I') {
kill(pid, SIGINT);
printf("Sent a SIGINT signal\n");
}
else if (c == 'k' || c == 'K') {
printf("About to send a SIGQUIT signal\n");
kill(pid, SIGQUIT);
printf("Done.....\n");
exit(0);
}
else
printf("Wrong keypress (%c). Try again\n", c);
}
}