-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsigchi.c
More file actions
38 lines (31 loc) · 711 Bytes
/
sigchi.c
File metadata and controls
38 lines (31 loc) · 711 Bytes
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
#include <sys/wait.h>
#include <stdio.h>
#include <unistd.h>
int main(int argc, char **argv)
{
pid_t chpid = fork();
if (! chpid) {
for(;;) usleep(5000);
return 0;
}
pid_t pid=getpid();
printf("parent pid: %d\n", pid);
//#define FPID ("/home/box/pid")
#define PPID ("./pid_parent")
#define CPID ("./pid_child")
FILE *f1=fopen(PPID, "w");
FILE *f2=fopen(CPID, "w");
if (NULL == f1 || NULL == f2) {
perror("fopen");
return(1);
}
int rc = fprintf(f1, "%d\0", pid);
fprintf(f2, "%d\0", chpid);
fflush(f1); fflush(f2);
printf("%d\n", rc);
waitpid(chpid, &rc, 0);
printf("child process killed: %d\n", rc);
for(;;) usleep(5000);
fclose(f1); fclose(f2);
return 0;
}