3 * Copyright (C) 2001 Simone Piccardi
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or (at
8 * your option) any later version.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 /****************************************************************
21 * Program IPCTestId.c:
22 * Program to test IPC identifiers
24 * Author: Simone Piccardi
27 * Usage: ipctestid -h give all info's
29 * $Id: IPCTestId.c,v 1.2 2002/08/19 17:34:23 piccardi Exp $
31 ****************************************************************/
33 * Include needed headers
35 #include <errno.h> /* error definitions and routines */
36 #include <stdlib.h> /* C standard library */
37 #include <unistd.h> /* unix standard library */
38 #include <stdio.h> /* standard I/O library */
39 #include <string.h> /* string functions */
40 #include <sys/ipc.h> /* SysV IPC functions */
41 #include <sys/msg.h> /* SysV Message Queue */
42 #include <sys/sem.h> /* SysV Semaphores */
43 #include <sys/shm.h> /* SysV Shared Memory */
45 #include "macros.h" /* My macros */
46 /* Help printing routine */
49 int main(int argc, char *argv[])
52 * Variables definition
55 int n = 5; /* default is 10 tryes */
56 char type='q'; /* default is use queues */
59 * Input section: decode command line parameters
62 opterr = 0; /* don't want writing to stderr */
63 while ( (i = getopt(argc, argv, "hqsmn:")) != -1) {
68 case 'h': /* help option */
69 printf("Wrong -h option use\n");
73 case 'q': /* Message Queue */
74 debug("Message Queue\n");
77 case 's': /* Semaphore */
81 case 'm': /* Shared Memory */
82 debug("Shared Memory\n");
85 case 'n': /* Number of tryes */
86 debug("Number of tryes\n");
87 n = strtol(optarg, NULL, 10);
89 default: /* should not reached */
93 /* ***********************************************************
95 * Options processing completed
99 * ***********************************************************/
101 case 'q': /* Message Queue */
102 debug("Message Queue Try\n");
103 for (i=0; i<n; i++) {
104 id = msgget(IPC_PRIVATE, IPC_CREAT|0666);
105 printf("Identifier Value %d \n", id);
106 msgctl(id, IPC_RMID, NULL);
109 case 's': /* Semaphore */
110 debug("Semaphore\n");
111 for (i=0; i<n; i++) {
112 id = semget(IPC_PRIVATE, 1, IPC_CREAT|0666);
113 printf("Identifier Value %d \n", id);
114 semctl(id, 0, IPC_RMID);
117 case 'm': /* Shared Memory */
118 debug("Shared Memory\n");
119 for (i=0; i<n; i++) {
120 id = shmget(IPC_PRIVATE, 1000, IPC_CREAT|0666);
121 printf("Identifier Value %d \n", id);
122 shmctl(id, IPC_RMID, NULL);
125 default: /* should not reached */
131 * routine to print usage info and exit
134 printf("Program ipctestid : test IPC identifier number assignment\n");
136 printf(" ipctestid [-h] [-qsm] [-n N] \n");
137 printf(" -h print this help\n");
138 printf(" -q try for message queue identifiers\n");
139 printf(" -s try for semaphore identifiers\n");
140 printf(" -m try for shared memory identifiers\n");
141 printf(" -n XX try XX times\n");