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 ****************************************************************/
31 * Include needed headers
33 #include <errno.h> /* error definitions and routines */
34 #include <stdlib.h> /* C standard library */
35 #include <unistd.h> /* unix standard library */
36 #include <stdio.h> /* standard I/O library */
37 #include <string.h> /* C strings library */
38 #include <sys/ipc.h> /* SysV IPC functions */
39 #include <sys/msg.h> /* SysV message queues */
40 #include <sys/sem.h> /* SysV semaphores */
41 #include <sys/shm.h> /* SysV shared memory */
43 #include "macros.h" /* My macros */
44 /* Help printing routine */
47 int main(int argc, char *argv[])
50 * Variables definition
53 int n = 5; /* default is 10 tryes */
54 char type='q'; /* default is use queues */
57 * Input section: decode command line parameters
60 opterr = 0; /* don't want writing to stderr */
61 while ( (i = getopt(argc, argv, "hqsmn:")) != -1) {
66 case 'h': /* help option */
67 printf("Wrong -h option use\n");
71 case 'q': /* Message Queue */
72 debug("Message Queue\n");
75 case 's': /* Semaphore */
79 case 'm': /* Shared Memory */
80 debug("Shared Memory\n");
83 case 'n': /* Number of tryes */
84 debug("Number of tryes\n");
85 n = strtol(optarg, NULL, 10);
87 default: /* should not reached */
91 /* ***********************************************************
93 * Options processing completed
97 * ***********************************************************/
99 case 'q': /* Message Queue */
100 debug("Message Queue Try\n");
101 for (i=0; i<n; i++) {
102 id = msgget(IPC_PRIVATE, IPC_CREAT|0666);
103 printf("Identifier Value %d \n", id);
104 msgctl(id, IPC_RMID, NULL);
107 case 's': /* Semaphore */
108 debug("Semaphore\n");
109 for (i=0; i<n; i++) {
110 id = semget(IPC_PRIVATE, 1, IPC_CREAT|0666);
111 printf("Identifier Value %d \n", id);
112 semctl(id, 0, IPC_RMID);
115 case 'm': /* Shared Memory */
116 debug("Shared Memory\n");
117 for (i=0; i<n; i++) {
118 id = shmget(IPC_PRIVATE, 1000, IPC_CREAT|0666);
119 printf("Identifier Value %d \n", id);
120 shmctl(id, IPC_RMID, NULL);
123 default: /* should not reached */
129 * routine to print usage info and exit
132 printf("Program ipctestid : test IPC identifier number assignment\n");
134 printf(" ipctestid [-h] [-qsm] [-n N] \n");
135 printf(" -h print this help\n");
136 printf(" -q try for message queue identifiers\n");
137 printf(" -s try for semaphore identifiers\n");
138 printf(" -m try for shared memory identifiers\n");
139 printf(" -n XX try XX times\n");