Linux Programming--IPC Status Commands (chapter 14th)

Source: Internet
Author: User
Tags message queue semaphore

14.5 IPC Status Commands Although the X/open specification does not define them, most Linux systems provide a set of commands to access IPC information from the command line and to clean up the free IPC mechanism. They are IPCS and IPCRM commands, which are useful for developing programs.
An annoying problem with the IPC mechanism is that a program that writes the wrong program or fails for some reason leaves its IPC resources (such as the data in the message queue) in the system, and these resources remain in the system for a long time after the program ends. This will cause the new call to execute to fail on the program, Because the program expects to start with a clean system, it actually finds some legacy resources. The Status command (IPCS) and the Delete command (IPCRM) provide a way to check and clean up the IPC mechanism.
14.5.1 Display semaphore status to check the status of the semaphore in the system, you can use the command ipcs-s. If there is a semaphore in the system, the output in the following format is given:
$ ipcs-s


You can use the command Ipcrm to remove semaphores that are left in the system by the program as a result of an unexpected situation. To remove the semaphore above, the command used (on the Linux system) is as follows:

$ ipcrm-s 768
14.5.2 shows that shared memory status is similar to semaphores, and many systems provide command-line programs to access the details of shared memory. They're orders ipcs-m and ipcrm-m<id>.
The following is a sample output of some of the ipcs-m commands:
$ ipcs-m

The purpose of the Ipcrm-m <id> command is to delete shared memory. This command is useful if the program fails to clean up shared memory because it failed to run.
14.5.3 Display Message Queue status commands for Message Queuing are ipcs-q and ipcrm-q <id>
Here are some of the output from the command ipcs-q:

14.6 Summary In this chapter, there are 3 mechanisms for interprocess communication, which first appear in the UNIX System v.2 version and are used since the early version of Linux. These mechanisms are semaphores, Shared memory and Message Queuing. Describes the complex features they provide and how they are provided. Once these features are understood, they can provide a powerful solution to the needs of many interprocess communications.

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Linux Programming--IPC Status Commands (chapter 14th)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.