ipc_shm.c revision 12e24427845a1e97e6ffd65153a3752c6d02de7d
1#include <stdio.h>
2#include <sys/shm.h>
3
4int
5main(void)
6{
7	int id = shmget(IPC_PRIVATE, 1, 0600);
8	if (id < 0)
9		return 77;
10	printf("shmget\\(IPC_PRIVATE, 1, 0600\\) += %d\n", id);
11
12	int rc = 1;
13
14	struct shmid_ds ds;
15	int max = shmctl(0, SHM_INFO, &ds);
16	if (max < 0)
17		goto fail;
18	printf("shmctl\\(0, SHM_INFO, %p\\) += %d\n", &ds, max);
19
20	if (shmctl(id, SHM_STAT, &ds) != id)
21		goto fail;
22	printf("shmctl\\(%d, SHM_STAT, %p\\) += %d\n", id, &ds, id);
23
24	rc = 0;
25
26fail:
27	if (shmctl(id, IPC_RMID, 0) < 0)
28		return 1;
29	printf("shmctl\\(%d, IPC_RMID, 0\\) += 0\n", id);
30	return rc;
31}
32