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 */
28 * shmctl(2) shmget(2) shmat(2) shmdt(2)
31 * Create a shared memory segment. Attach it twice at an address
32 * that is provided by the system. Detach the previously attached
33 * segments from the process.
39 #include <sys/types.h>
50 char *TCID
="shmt08"; /* Test program identifier. */
51 int TST_TOTAL
=2; /* Total number of test cases. */
52 extern int Tst_count
; /* Test Case counter for tst_* routines */
61 char *cp
=NULL
, *cp1
=NULL
;
64 key
= (key_t
) getpid() ;
66 /*-------------------------------------------------------*/
69 if ((shmid
= shmget(key
, 24*K_1
, IPC_CREAT
|0666)) < 0) {
71 tst_resm(TFAIL
,"Error: shmget: shmid = %d, errno = %d\n",
76 cp
= (char *) shmat(shmid
, (void *)0, 0);
77 if (cp
== (char *)-1) {
78 tst_resm(TFAIL
,"shmat1 Failed");
83 cp1
= (char *) shmat(shmid
, (void *)0, 0);
84 if (cp1
== (char *)-1) {
90 tst_resm(TPASS
,"shmget,shmat");
92 /*--------------------------------------------------------*/
97 tst_resm(TFAIL
,"shmdt:cp") ;
100 if (shmdt(cp1
) < 0 ) {
102 tst_resm(TFAIL
,"shmdt:cp1") ;
105 tst_resm(TPASS
,"shmdt");
107 /*---------------------------------------------------------*/
111 /*---------------------------------------------------------*/
118 if (shmctl(shmid
, IPC_RMID
, NULL
) == -1) {
121 "shmctl Failed to remove: shmid = %d, errno = %d\n",