1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
|
/*-------------------------------------------------------------------------
*
* tstshm.c
* Test of System V Shared Memory Emulation
*
* Copyright (c) 1999, repas AEG Automation GmbH
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/port/qnx4/Attic/tstshm.c,v 1.1 1999/12/16 16:52:52 momjian Exp $
*
*-------------------------------------------------------------------------
*/
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/shm.h>
int main( int argc, char **argv )
{
int c, errflg = 0;
char s[80];
key_t key = 0x1000;
size_t size = 256;
int shmid = -1;
caddr_t addr = NULL;
optarg = NULL;
while( !errflg && ( c = getopt( argc, argv, "k:s:" ) ) != -1 ) {
switch( c ) {
case 'k': key = atoi( optarg ); break;
case 's': size = atoi( optarg ); break;
default: errflg++;
}
}
if( errflg ) {
printf( "usage: tstshm [-k key] [-s size]\n" );
exit( 1 );
}
do {
printf( "shm(g)et, shm(a)t, shm(d)t, shm(c)tl, (w)rite, (r)ead, e(x)it: " );
scanf( "%s", s );
switch( s[0] ) {
case 'g':
shmid = shmget( key, size, IPC_CREAT | SHM_R | SHM_W );
if( shmid == -1 ) perror( "shmget" );
break;
case 'a':
addr = shmat( shmid, NULL, 0 );
if( addr == ( void * )-1 ) perror( "shmat" );
break;
case 'd':
if( shmdt( addr ) == -1 ) perror( "shmdt" );
else addr = NULL;
break;
case 'c':
if( shmctl( shmid, IPC_RMID, NULL ) == -1 ) perror( "shmctl" );
else shmid = -1;
break;
case 'w':
printf( "String to write: " );
scanf( "%s", addr );
break;
case 'r':
puts( addr );
break;
}
}
while( s[0] != 'x' );
return 0;
}
|