]> cygwin.com Git - cygwin-apps/cygutils.git/blob - src/ipc/ipcrm.c
Add ipcs, ipcrm, ipck progs from cygutils
[cygwin-apps/cygutils.git] / src / ipc / ipcrm.c
1 /* $Id$ */
2
3 /*
4 * ipcrm
5 *
6 * Copyright (C) 1997 Philippe CHAPUY
7 * Copyright (C) 1998 Ludovic LANGE
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 */
23
24 /*
25 * HISTORY:
26 * --------
27 *
28 * 13/05/1998 : Version 1.00 released
29 * First public release
30 * adress any comments to llange@capgemini.fr
31 * 2003/06/13 : (C. Wilson) Ported to the cygutils package from
32 * the cygipc package.
33 *
34 */
35
36 /************************************************************************/
37 /* Philippe Chapuy, le 19/05/97 */
38 /************************************************************************/
39
40 #if HAVE_CONFIG_H
41 # include "config.h"
42 #endif
43
44 #include "common.h"
45
46 #if HAVE_SYS_IPC_H
47 # include <sys/ipc.h>
48 # if HAVE_SYS_SEM_H
49 # include <sys/sem.h>
50 # endif
51 # if HAVE_SYS_SHM_H
52 # include <sys/shm.h>
53 # endif
54 # if HAVE_SYS_MSG_H
55 # include <sys/msg.h>
56 # endif
57 #endif
58
59 /* These includes moved to common.h
60 #include <unistd.h>
61 #include <stdlib.h>
62 #include <stdio.h>
63 */
64
65 /* arg for semctl system calls. */
66 union semun {
67 int val; /* value for SETVAL */
68 struct semid_ds *buf; /* buffer for IPC_STAT & IPC_SET */
69 ushort *array; /* array for GETALL & SETALL */
70 struct seminfo *__buf; /* buffer for IPC_INFO */
71 void *__pad;
72 };
73
74 int main(int argc, char **argv)
75 {
76 int id;
77 union semun arg;
78 int LBoucle ;
79
80 arg.val = 0;
81
82 if (argc < 3 || strlen(argv[1]) < 3) {
83 printf ("usage: %s [shm | msg | sem] id1 ... idn\n", argv[0]);
84 exit (1);
85 }
86 id = atoi (argv[2]);
87 switch (argv[1][1]) {
88 case 'h':
89 for (LBoucle = 2; LBoucle < argc; LBoucle++)
90 {
91 id = atoi (argv[LBoucle]) ;
92 if (!shmctl (id, IPC_RMID, NULL))
93 continue ;
94 perror ("shmctl ");
95 }
96 exit (1);
97
98 case 'e':
99 for (LBoucle = 2; LBoucle < argc; LBoucle++)
100 {
101 id = atoi (argv[LBoucle]) ;
102 if (!semctl (id, 0, IPC_RMID, arg))
103 continue ;
104 perror ("semctl ");
105 }
106 exit (1);
107
108 case 's':
109 for (LBoucle = 2; LBoucle < argc; LBoucle++)
110 {
111 id = atoi (argv[LBoucle]) ;
112 if (!msgctl (id, IPC_RMID, NULL))
113 continue ;
114 perror ("msgctl ");
115 }
116 exit (1);
117
118 default:
119 printf ("usage: %s [-shm | -msg | -sem] id\n", argv[0]);
120 exit (1);
121 }
122 sleep(2) ;
123 printf ("resource deleted\n");
124 return 0;
125 }
126
This page took 0.03902 seconds and 5 git commands to generate.