blob: 62a59b1e9e43a13868bd0af9129000f4ffddf594 [file] [log] [blame]
lh9ed821d2023-04-07 01:36:19 -07001#include <stdio.h>
2#include <string.h>
3#include <errno.h>
4#include <sys/types.h>
5#include <sys/ipc.h>
6#include <sys/sem.h>
7
8int main(void)
9{
10 int k, r;
11 union semun {
12 int val;
13 struct semid_ds *buf;
14 unsigned short int *array;
15 struct seminfo *__buf;
16 } sd;
17 struct semid_ds sd_buf;
18
19 k = semget(IPC_PRIVATE, 10, IPC_CREAT | 0666 );
20 printf("semget(IPC_CREAT) = %d\n", k);
21
22 if (k < 0) {
23 fprintf(stderr, "semget failed: %s\n", strerror(errno));
24 return 1;
25 }
26
27 sd.buf = &sd_buf;
28 r = semctl(k, 0, IPC_STAT, sd);
29 printf("semctl(k) = %d\n", r);
30
31 if (r < 0) {
32 perror("semctl IPC_STAT failed");
33 return 1;
34 }
35
36 printf("sem_nsems = %lu\n", sd_buf.sem_nsems);
37 if (sd_buf.sem_nsems != 10) {
38 fprintf(stderr, "failed: incorrect sem_nsems!\n");
39 return 1;
40 }
41
42 printf("succeeded\n");
43
44 return 0;
45}