11.01.2013 Views

IBM AIX Continuous Availability Features - IBM Redbooks

IBM AIX Continuous Availability Features - IBM Redbooks

IBM AIX Continuous Availability Features - IBM Redbooks

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

}<br />

}<br />

perror("parent:shmget()");<br />

return (1);<br />

}<br />

if ( (data=shmat(id,(void *)0, 0)) == (char*) (-1) ){<br />

perror("parent:shmat()");<br />

return (1);<br />

}<br />

if (rc=ukey_protect(data,one_page,pkey)){<br />

perror("parent:ukey_protect(pkey)");<br />

exit(1);<br />

}<br />

oldset=ukeyset_activate(pkeyset,UKA_ADD_KEYS);<br />

if (oldset==UKSET_INVALID){<br />

printf("parent:ukeyset_activate() failed");<br />

exit (1);<br />

}<br />

sleep(2);<br />

printf("parent:READ1 =[%s]\n",data);<br />

strcpy(data+strlen(data),"ABCD");<br />

printf("parent:WRITE1=[ABCD]\n");<br />

sleep(2);<br />

if (shmdt(data)==-1){<br />

perror("parent:shmdt()");<br />

return (1);<br />

}<br />

if (shmctl(id,IPC_RMID,0)){<br />

perror("parent:shmctl()");<br />

return (1);<br />

}<br />

return (0);<br />

We compiled the program:<br />

# cc -g -o ukey1 ukey1.c<br />

We gave the child process write (no-read) access on the shared memory segment, and<br />

executed it as shown in Example 3-32.<br />

Example 3-32 Executing program with write access to shared memory<br />

# ./ukey1 write<br />

parent:pagesize=4096<br />

child:data=0x30000000<br />

parent:READ1 =[]<br />

parent:WRITE1=[ABCD]<br />

# ls core<br />

core<br />

# dbx ukey1 core<br />

Type 'help' for help.<br />

[using memory image in core]<br />

reading symbolic information ...<br />

Segmentation fault in strlen at 0xd010da00<br />

0xd010da00 (strlen) 89030000 lbz r8,0x0(r3)<br />

(dbx) where<br />

Chapter 3. <strong>AIX</strong> advanced continuous availability tools and features 105

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!