From 1c8d37efdba437ab42d3d14257b7eb6adf7f2e4f Mon Sep 17 00:00:00 2001 From: toni Date: Mon, 26 Oct 2015 00:30:52 +0100 Subject: exported UI IPC --- tests/semtest2.c | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 tests/semtest2.c (limited to 'tests/semtest2.c') 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 +#include +#include +#include +#include +#include +#include +#include + +#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); +} + -- cgit v1.2.3