blob: c015df8012fa02a9224d4724158982d83a983ca9 (
plain)
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
42
43
|
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <semaphore.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <fcntl.h>
#include "../ui_ipc.h"
pid_t child;
#define LOG(cmd) fprintf(stderr, "%s\n", cmd);
int main(int argc, char **argv) {
if (ui_ipc_init(1) != 0) {
perror("ui_ipc_init");
exit(1);
}
if ( (child = fork()) == 0 ) {
/* child */
sleep(1);
LOG("child: sempost");
ui_ipc_sempost(SEM_RD);
LOG("child: done");
sleep(1);
exit(0);
} else if (child > 0) {
/* parent */
LOG("parent: semwait");
ui_ipc_semwait(SEM_RD);
LOG("parent: waitpid");
waitpid(child, NULL, 0);
} else if (child < 0) {
perror("fork");
exit(1);
}
ui_ipc_free(1);
exit(0);
}
|