3 * Copyright (c) International Business Machines Corp., 2002
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
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
13 * the GNU 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 /* 12/20/2002 Port to LTP robbiew@us.ibm.com */
21 /* 06/30/2001 Port to Linux nsharoff@us.ibm.com */
25 * shmt10.c - test simultaneous shmat/shmdt
28 * shmget, shmat, shmdt, shmctl
31 * Create a shared memory segment and fork a child. Both
32 * parent and child spin in a loop attaching and detaching
33 * the segment. After completing the specified number of
34 * iterations, the child exits and the parent deletes the
39 * -i # of iterations, default 500
45 #include <sys/types.h>
60 char *TCID
="shmt10"; /* Test program identifier. */
61 int TST_TOTAL
=2; /* Total number of test cases. */
62 extern int Tst_count
; /* Test Case counter for tst_* routines */
72 int main(int argc
, char *argv
[])
81 key
= (key_t
)getpid();
82 signal(SIGTERM
, fini
);
84 /*--------------------------------------------------------*/
86 while ((c
= getopt(argc
, argv
, "i:")) != EOF
) {
92 tst_resm(TCONF
, "usage: %s [-i <# iterations>]", argv
[0]);
98 /*------------------------------------------------------------------------*/
100 if ((shmid
= shmget(key
, SIZE
, IPC_CREAT
|0666)) < 0) {
101 tst_resm(TFAIL
,"shmget") ;
102 tst_resm(TFAIL
, "Error: shmid = %d\n", shmid
) ;
109 tst_resm(TBROK
,"fork failed");
116 for (i
= 0; i
< iter
; i
++) {
117 if ((c1
= (char *) shmat(shmid
, (void *)0, 0)) == (char *)-1) {
119 "Error shmat: iter %d, shmid = %d\n", i
, shmid
);
124 "Error: shmdt: iter %d ", i
) ;
128 while ( wait(&st
) < 0 && errno
== EINTR
)
130 tst_resm(TPASS
,"shmat,shmdt");
131 /*------------------------------------------------------------------------*/
136 /*------------------------------------------------------------------------*/
143 if (shmctl(shmid
, IPC_RMID
, NULL
) == -1) {
146 "shmctl Failed to remove: shmid = %d, errno = %d\n",
159 for (i
= 0; i
< iter
; i
++) {
160 if ((c1
= (char *) shmat(shmid
, (void *)0, 0)) == (char *)-1) {
162 "Error:child proc: shmat: iter %d, shmid = %d\n",
168 "Error: child proc: shmdt: iter %d ", i
);