User Utilities


User Utilities

GNU/Linux provides the ipcs command to explore IPC assets from the command line (including shared memory segments that are visible to the user). The ipcs utility provides information on shared memory segments as well as message queues and semaphores. We ll investigate its use for shared memory segments here.

The general form of the ipcs utility for shared memory segments is:

 $  ipcs -m  

This presents all of the shared memory segments that are visible to the process. Let s start by creating a shared memory segment (as shown in Listing 17.1):

 $  ./shmcreate  Created a shared memory segment 163840 [mtj@camus ch17]$  ipcs -m  Shared Memory Segments  key        shmid     owner      perms      bytes      nattch     status 0x000003e7 163840    mtj        666        4096       0 $ 

We see here a new shared memory segment being available ( 0x3e7 = 999 ). Its size is 4,096 bytes, and we see that there are currently no attaches to this segment ( nattch = 0 ). If we wanted to dig into this segment deeper, we could specify this shared memory segment specifically to ipcs . This is done with ipcs using the -i option:

 $  ipcs -m -i 163840  Shared memory Segment shmid=163840 uid=500 gid=500 cuid=500        cgid=500 mode=0666       access_perms=0666 bytes=4096      lpid=0  cpid=15558      nattch=0 att_time=Not set det_time=Not set change_time=Thu May 20 11:44:44 2004 $ 

We now see some more detailed information, including the attach, detach and change times, last pid, created pid, and so on.

Finally, we can remove the shared memory segment using the ipcrm command. To remove our previously created shared memory segment, we simply provide the shared memory identifier, as:

 $  ipcrm -m 163840  $ 



GNU/Linux Application Programming
GNU/Linux Application Programming (Programming Series)
ISBN: 1584505680
EAN: 2147483647
Year: 2006
Pages: 203
Authors: M. Tim Jones

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net