diff options
author | Eric Andersen <andersen@codepoet.org> | 2002-08-24 21:23:58 +0000 |
---|---|---|
committer | Eric Andersen <andersen@codepoet.org> | 2002-08-24 21:23:58 +0000 |
commit | e44c028c15f596875449eed8885824add58e6865 (patch) | |
tree | e632ced907988152f41e0a8b75e4a0bb308eba61 /test/misc/sem.c | |
parent | 20dd264683eb83c0a3b701fa10137372ca71c066 (diff) |
Simple shared memory test
Diffstat (limited to 'test/misc/sem.c')
-rw-r--r-- | test/misc/sem.c | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/test/misc/sem.c b/test/misc/sem.c new file mode 100644 index 000000000..7606fd180 --- /dev/null +++ b/test/misc/sem.c @@ -0,0 +1,43 @@ +#include <stdio.h> +#include <sys/types.h> +#include <sys/ipc.h> +#include <sys/sem.h> + +int main(void) +{ + int k, r; + union semun { + int val; + struct semid_ds *buf; + unsigned short int *array; + struct seminfo *__buf; + } sd; + struct semid_ds sd_buf; + + k = semget(IPC_PRIVATE, 10, IPC_CREAT | 0666 ); + printf("%d\n", k); + + if (k < 0) { + printf("semget failed: %m\n"); + return 1; + } + + sd.buf = &sd_buf; + r = semctl(k, 0, IPC_STAT, sd); + printf("%d\n", r); + + if (r < 0) { + printf("semctl IPC_STAT failed: %m\n"); + return 1; + } + + printf("sem_nsems = %lu\n", sd_buf.sem_nsems); + if (sd_buf.sem_nsems != 10) { + printf("failed: incorrect sem_nsems!\n"); + return 1; + } + + printf("succeeded\n"); + + return 0; +} |