aboutsummaryrefslogtreecommitdiff
path: root/tests/semtest2.c
diff options
context:
space:
mode:
Diffstat (limited to 'tests/semtest2.c')
-rw-r--r--tests/semtest2.c43
1 files changed, 43 insertions, 0 deletions
diff --git a/tests/semtest2.c b/tests/semtest2.c
new file mode 100644
index 0000000..c015df8
--- /dev/null
+++ b/tests/semtest2.c
@@ -0,0 +1,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);
+}
+