10 IPCS Command Examples (With IPC Introduction)

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 11

10 IPCS Command Examples (With IPC Introduction)

4/19/11 3:59 AM

Home About Free eBook Archives Best of the Blog Contact


Ads by Google Linux Unix Basic Unix Command Basic Linux Training

10 IPCS Command Examples (With IPC Introduction)


by Sasikala on August 12, 2010 IPC stands for Inter-process Communication. This technique allows the processes to communicate with each another. Since each process has its own address space and unique user space, how does the process communicate each other? The answer is Kernel, the heart of the Linux operating system that has access to the whole memory. So we can request the kernel to allocate the space which can be used to communicate between processes. The process can also communicate by having a file accessible to both the processes. Processes can open, and read/write the file, which requires lot of I/O operation that consumes time.

Different Types of IPCS


There are various IPCs which allows a process to communicate with another processes, either in the same computer or different computer in the same network.
http://www.thegeekstuff.com/2010/08/ipcs-command-examples/ Page 1 of 11

10 IPCS Command Examples (With IPC Introduction)

4/19/11 3:59 AM

Pipes Provides a way for processes to communicate with each another by exchanging messages. Named pipes provide a way for processes running on different computer systems to communicate over the network. Shared Memory Processes can exchange values in the shared memory. One process will create a portion of memory which other process can access. Message Queue It is a structured and ordered list of memory segments where processes store or retrieve data. Semaphores Provides a synchronizing mechanism for processes that are accessing the same resource. No data is passed with a semaphore; it simply coordinates access to shared resources.

10 IPCS Command Example


ipcs is a UNIX / Linux command, which is used to list the information about the inter-process communication ipcs command provides a report on System V IPCS (Message queue, Semaphore, and Shared memory).

IPCS Example 1: List all the IPC facility


ipcs command with -a option lists all the IPC facilities which has read access for the current process. It provides details about message queue, semaphore and shared memory.

# ipcs -a ------ Shared Memory Segments -------key shmid owner perms 0xc616cc44 1056800768 oracle 660 0x0103f577 323158020 root 664 0x0000270f 325713925 root 666 ------ Semaphore Arrays -------key semid owner perms 0x0103eefd 0 root 664 0x0103eefe 32769 root 664 bytes 4096 966 1 nsems 1 1 nattch 0 1 2 status

http://www.thegeekstuff.com/2010/08/ipcs-command-examples/

Page 2 of 11

10 IPCS Command Examples (With IPC Introduction)

4/19/11 3:59 AM

0x4b0d4514 1094844418 oracle ------ Message Queues -------key msqid owner 0x000005a4 32768 root

660 perms 644

204 used-bytes 0 messages 0

All the IPC facility has unique key and identifier, which is used to identify an IPC facility.

IPCS Example 2: List all the Message Queue


ipcs with option -q, lists only message queues for which the current process has read access.
$ ipcs -q ------ Message Queues -------key msqid owner 0x000005a4 32768 root perms 644 used-bytes 0 messages 0

IPCS Example 3. List all the Semaphores


ipcs -s option is used to list the accessible semaphores.
# ipcs -s ------ Semaphore Arrays -------key semid owner perms 0x0103eefd 0 root 664 0x0103eefe 32769 root 664 0x4b0d4514 1094844418 oracle 660 nsems 1 1 204

IPCS Example 4. List all the Shared Memory


ipcs -m option with ipcs command lists the shared memories.
# ipcs -m ------ Shared Memory Segments -------key shmid owner perms 0xc616cc44 1056800768 oracle 660 0x0103f577 323158020 root 664 0x0000270f 325713925 root 666 bytes 4096 966 1 nattch 0 1 2 status

IPCS Example 5. Detailed information about an IPC facility


ipcs -i option provides detailed information about an ipc facility.
# ipcs -q -i 32768 Message Queue msqid=32768 uid=0 gid=0 cuid=0 cgid=0 cbytes=0 qbytes=65536 send_time=Not set rcv_time=Not set mode=0644 qnum=0 lspid=0 lrpid=0

http://www.thegeekstuff.com/2010/08/ipcs-command-examples/

Page 3 of 11

10 IPCS Command Examples (With IPC Introduction)

4/19/11 3:59 AM

change_time=Thu Aug

5 13:30:22 2010

Option -i with -q provides information about a particular message queue. Option -i with -s provides semaphore details. Option -i with -m provides details about a shared memory.

IPCS Example 6. Lists the Limits for IPC facility


ipcs -l option gives the system limits for each ipc facility.
# ipcs -m -l ------ Shared Memory Limits -------max number of segments = 4096 max seg size (kbytes) = 67108864 max total shared memory (kbytes) = 17179869184 min seg size (bytes) = 1

The above command gives the limits for shared memory. -l can be combined with -q and -s to view the limits for message queue and semaphores respectively. Single option -l gives the limits for all three IPC facilities.
# ipcs -l

IPCS Example 7. List Creator and Owner Details for IPC Facility
ipcs -c option lists creator userid and groupid and owner userid and group id. This option can be combined with -m, -s and -q to view the creator details for specific IPC facility.
# ipcs -m -c ------ Shared Memory Segment Creators/Owners -------shmid perms cuid cgid uid 1056800768 660 oracle oinstall oracle 323158020 664 root root root 325713925 666 root root root gid oinstall root root

IPCS Example 8. Process ids that accessed IPC facility recently


ipcs -p option displays creator id, and process id which accessed the corresponding ipc facility very recently.
# ipcs -m -p ------ Shared Memory Creator/Last-op -------shmid owner cpid lpid 1056800768 oracle 16764 5389 323158020 root 2354 2354 325713925 root 20666 20668

-p also can be combined with -m,-s or -q.

IPCS Example 9. Last Accessed Time


http://www.thegeekstuff.com/2010/08/ipcs-command-examples/ Page 4 of 11

10 IPCS Command Examples (With IPC Introduction)

4/19/11 3:59 AM

ipcs -t option displays last operation time in each ipc facility. This option can also be combined with -m, -s or -q to print for specific type of ipc facility. For message queue, -t option displays last sent and receive time, for shared memory it displays last attached (portion of memory) and detached timestamp and for semaphore it displays last operation and changed time details.
# ipcs -s -t ------ Semaphore Operation/Change Times -------semid owner last-op last-changed 0 root Thu Aug 5 12:46:52 2010 Tue Jul 13 10:39:41 2010 32769 root Thu Aug 5 11:59:10 2010 Tue Jul 13 10:39:41 2010 1094844418 oracle Thu Aug 5 13:52:59 2010 Thu Aug 5 13:52:59 2010

IPCS Example 10. Status of current usage


ipcs with -u command displays current usage for all the IPC facility. This option can be combined with a specific option to display the status for a particular IPC facility.
# ipcs -u ------ Shared Memory Status -------segments allocated 30 pages allocated 102 pages resident 77 pages swapped 0 Swap performance: 0 attempts 0 successes ------ Semaphore Status -------used arrays = 49 allocated semaphores = 252 ------ Messages: Status -------allocated queues = 1 used headers = 0 used space = 0 bytes

Bookmark/Share this Article Leave a Comment

If you enjoyed this article, you might also like..


1. 50 Linux Sysadmin Tutorials 2. 50 Most Frequently Used Linux Commands (With Examples) 3. Mommy, I found it! 15 Practical Linux Find Command Examples 4. Turbocharge PuTTY with 12 Powerful Add-Ons 5. 12 Amazing and Essential Linux Books To Enrich Your Brain

http://www.thegeekstuff.com/2010/08/ipcs-command-examples/

Page 5 of 11

10 IPCS Command Examples (With IPC Introduction)

4/19/11 3:59 AM

Tags: IPCS AIX, IPCS Solaris, IPCS Unix, Kernel shmmax, semop, Shared Memory Segment, shmat, shmget { 5 comments read them below or add one } 1 b-rad August 12, 2010 at 8:34 am I have never seen or used the ipcs command before, so its very interesting. But, what can I do with this info? Whats a practical usage scenario for using these commands? 2 vinc August 12, 2010 at 9:19 am Interesting article. But Im missing some practical example of usage. For example I need to prevent that some script will run twice and one moment. Can I use semaphore for it? And how? 3 djatlantic August 12, 2010 at 12:36 pm The practical usage is to tune the parameters of IPC so that your database (Oracle, or ..), HPC applications can access these resources and use them in such ways to enable them to work better and access bigger chunks of share memory. And there might be some other more practical and typical usages of IPC too. 4 rasta_freak August 14, 2010 at 1:27 am Author forgot to mention than IPC is used (directly) in languages like C/C++, in others it is used indirectly most of the time (very few of them gives direct control of IPC shell does not). There are system/libc calls to create message queues/shared memory segments/semaphores, to push messages,
http://www.thegeekstuff.com/2010/08/ipcs-command-examples/ Page 6 of 11

10 IPCS Command Examples (With IPC Introduction)

4/19/11 3:59 AM

poll, and read them, write/read shared memory, and set/reset semaphores. It is fastest possible communication between processes if one process puts message on queue, other process can read it as soon as scheduler gives it run-time (cpu-time). ipcs command is used for debugging primarily, in development of programs to check that communication is working as expected, to check that no stale messages/memory are being left out, and to clean up the mess if programs crash/have bugs. If you dont write your programs in C/C++, and dont use IPC in them ipcs command is useless to you. You could write front-ends for creating/pushing/polling/reading to be used in shell, but it would be slower than using file communication in tmpfs (because of overhead of invoking other process, checking status, etc). 5 Ramesh Natarajan August 17, 2010 at 11:28 pm @b-rad, @vinc, Thanks a lot for your suggestion. Well post a practical usage of IPCS as a quick FAQ very soon. @djatlantic, @rasta_freak, Thanks for explaining in detail about how IPCS can be used. Leave a Comment Name E-mail Website

Notify me of followup comments via e-mail


Submit

Previous post: How to Allow MySQL Client to Connect to Remote MySQL server Next post: 10 Things Any Monitoring Software Should Do (Nagios Does it) Sign up for our free email newsletter RSS Twitter
you@address.com Sign Up

Facebook

http://www.thegeekstuff.com/2010/08/ipcs-command-examples/

Page 7 of 11

10 IPCS Command Examples (With IPC Introduction)

4/19/11 3:59 AM

Search

EBOOKS

http://www.thegeekstuff.com/2010/08/ipcs-command-examples/

Page 8 of 11

10 IPCS Command Examples (With IPC Introduction)

4/19/11 3:59 AM

POPULAR POSTS
12 Amazing and Essential Linux Books To Enrich Your Brain and Library 50 UNIX / Linux Sysadmin Tutorials 50 Most Frequently Used UNIX / Linux Commands (With Examples) How To Be Productive and Get Things Done Using GTD 30 Things To Do When you are Bored and have a Computer Linux Directory Structure (File System Structure) Explained with Examples Linux Crontab: 15 Awesome Cron Job Examples Get a Grip on the Grep! 15 Practical Grep Command Examples Unix LS Command: 15 Practical Examples 15 Examples To Master Linux Command Line History Top 10 Open Source Bug Tracking System Vi and Vim Macro Tutorial: How To Record and Play Mommy, I found it! -- 15 Practical Linux Find Command Examples 15 Awesome Gmail Tips and Tricks 15 Awesome Google Search Tips and Tricks RAID 0, RAID 1, RAID 5, RAID 10 Explained with Diagrams Can You Top This? 15 Practical Linux Top Command Examples Top 5 Best System Monitoring Tools Top 5 Best Linux OS Distributions How To Monitor Remote Linux Host using Nagios 3.0 Awk Introduction Tutorial 7 Awk Print Examples How to Backup Linux? 15 rsync Command Examples The Ultimate Wget Download Guide With 15 Awesome Examples Top 5 Best Linux Text Editors Packet Analyzer: 15 TCPDUMP Command Examples The Ultimate Bash Array Tutorial with 15 Examples 3 Steps to Perform SSH Login Without Password Using ssh-keygen & ssh-copy-id Unix Sed Tutorial: Advanced Sed Substitution Examples UNIX / Linux: 10 Netstat Command Examples The Ultimate Guide for Creating Strong Passwords 6 Steps to Secure Your Home Wireless Network
http://www.thegeekstuff.com/2010/08/ipcs-command-examples/ Page 9 of 11

10 IPCS Command Examples (With IPC Introduction)

4/19/11 3:59 AM

Turbocharge PuTTY with 12 Powerful Add-Ons

About The Geek Stuff

My name is Ramesh Natarajan. I will be posting instruction guides, how-to, troubleshooting tips and tricks on Linux, database, hardware, security and web. My focus is to write articles that will either teach you or help you resolve a problem. Read more about Ramesh Natarajan and the blog.
http://www.thegeekstuff.com/2010/08/ipcs-command-examples/ Page 10 of 11

10 IPCS Command Examples (With IPC Introduction)

4/19/11 3:59 AM

Support Us
Support this blog by purchasing one of my ebooks. Nagios Core 3 eBook: Monitor Everything, Be Proactive, and Sleep Well. Vim 101 Hacks eBook: Practical Examples for Becoming Fast and Productive in the Vim Editor.

Contact Us
Email Me : Use this Contact Form to get in touch me with your comments, questions or suggestions about this site. You can also simply drop me a line to say hello!. Follow us on Twitter Become a fan on Facebook Copyright 20082011 Ramesh Natarajan. All rights reserved | Terms of Service | Advertise

http://www.thegeekstuff.com/2010/08/ipcs-command-examples/

Page 11 of 11

You might also like