]>
cygwin.com Git - cygwin-apps/cygutils.git/blob - src/ipc/shmtool.c
3634eb7a42bc37f85e1802a33637a476799051c1
1 /*****************************************************************************
2 Excerpt from "Linux Programmer's Guide - Chapter 6"
3 (C)opyright 1994-1995, Scott Burkett
4 *****************************************************************************
6 *****************************************************************************
7 A command line tool for tinkering with shared memory
9 *****************************************************************************/
11 * This program is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation, either version 3 of the License, or
14 * (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program. If not, see <http://www.gnu.org/licenses/>.
24 * See the COPYING file for full license information.
45 fprintf (stderr
, "shmtool - A utility for tinkering with shared memory\n");
46 fprintf (stderr
, "\nUSAGE: shmtool (w)rite <text>\n");
47 fprintf (stderr
, " (r)ead\n");
48 fprintf (stderr
, " (d)elete\n");
49 fprintf (stderr
, " (m)ode change <octal mode>\n");
54 writeshm (int shmid
, char *segptr
, char *text
)
56 strcpy (segptr
, text
);
61 readshm (int shmid
, char *segptr
)
63 printf ("segptr: %s\n", segptr
);
69 shmctl (shmid
, IPC_RMID
, 0);
70 printf ("Shared memory segment marked for deletion\n");
74 changemode (int shmid
, char *mode
)
76 struct shmid_ds myshmds
;
78 /* Get current values for internal data structure */
79 shmctl (shmid
, IPC_STAT
, &myshmds
);
81 /* Display old permissions */
82 printf ("Old permissions were: %o\n", myshmds
.shm_perm
.mode
);
84 /* Convert and load the mode */
85 sscanf (mode
, "%o", &myshmds
.shm_perm
.mode
);
88 shmctl (shmid
, IPC_SET
, &myshmds
);
90 printf ("New permissions are : %o\n", myshmds
.shm_perm
.mode
);
94 main (int argc
, char *argv
[])
103 /* Create unique key via call to ftok() */
104 key
= ftok (".", 'S');
106 /* Open the shared memory segment - create if necessary */
107 if ((shmid
= shmget (key
, SEGSIZE
, IPC_CREAT
| IPC_EXCL
| 0666)) == -1)
109 printf ("Shared memory segment exists - opening as client\n");
111 /* Segment probably already exists - try as a client */
112 if ((shmid
= shmget (key
, SEGSIZE
, 0)) == -1)
120 printf ("Creating new shared memory segment\n");
123 /* Attach (map) the shared memory segment into the current process */
124 if ((segptr
= shmat (shmid
, 0, 0)) == ((char *) -1))
130 switch (tolower (argv
[1][0]))
133 writeshm (shmid
, segptr
, argv
[2]);
136 readshm (shmid
, segptr
);
142 changemode (shmid
, argv
[2]);
This page took 0.046286 seconds and 6 git commands to generate.