Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I have semaphore monitoring tool recently deploy. I am new to semaphores. I am thinking to clear all semaphores but don't know what would be the impact. If I clear the semaphore of the running process, will it stop from running?
If you walked up to railroad semaphore and arbitrarily changed it from red to green, what impact would that have to a running freight train?
Semaphores are very much like those railroad signals or traffic lights: they coordinate the simultaneous activities of multiple processes. If you fiddle with them externally, you will destroy the integrity of whatever they are doing, with unpredictable results.
I am amazed to hear of any tool that permits you to do any such thing.
The reason I asked because I have notice most of the result I found on the Internet usually ask for clearing all the semaphores. In Linux, it is easy to identify the process attached to it but I cannot find the similar option for Solaris and HPUX. It has a different option which makes me think why not clear all the semaphores instead.
The reason I asked because I have notice most of the result I found on the Internet usually ask for clearing all the semaphores. In Linux, it is easy to identify the process attached to it but I cannot find the similar option for Solaris and HPUX. It has a different option which makes me think why not clear all the semaphores instead.
Hi,
Can you share the links and resources where you've found this to be your conclusion?
Per sundialsvcs' point, not only are semaphores CPU process flow control, they are there for a reason and each of them are unique per process. For instance if you have an Ethernet driver which uses semaphores to protect the ingress data, this might be one use. And perhaps you have a totally different process such as a database process which uses semaphores to lock entries to avoid updates to a record during a brief timeframe. These are designed in semaphores, specific to the application using them. Finding a way to globally access and monitor them is not an unbelievable act, however globally resetting them may be catastrophic to those processes because the code segments assume they do have a semaphore once they've obtained it, and to yank it away means that all code running with the former assumption is now operating on an invalid assumption. And what happens when that same code goes to free the semaphore? What if it was a counting semaphore? Does it then become negative?
I have quite honestly never seen any control anywhere that lists semaphores and allows me to manipulate them externally.
- - - - -
The purpose of a semaphore is exactly like that of a railroad signal protecting a section of single-track that can be reached by a double-track: to enter the section, "your signal must be green." Everyone else's signal remains red until your train leaves the common section of single-track. Thus, the signal prevents any attempt for more than one train to use the same track (ouch!) at the same time.
I have quite honestly never seen any control anywhere that lists semaphores and allows me to manipulate them externally.
- - - - -
The purpose of a semaphore is exactly like that of a railroad signal protecting a section of single-track that can be reached by a double-track: to enter the section, "your signal must be green." Everyone else's signal remains red until your train leaves the common section of single-track. Thus, the signal prevents any attempt for more than one train to use the same track (ouch!) at the same time.
A semaphore is a memory location, or range of it in a structure. If you manipulate the code which grants and free semaphores, you can certainly be within the bounds of seeing all the semaphores the system has. However it does not mean that you are supposed to change them.
Processes should clean up their semaphore-arrays, shared-memory segments and so forth, and I would not consider it advisable to remove them because the probability of messing something up is very high. There's a lot of code out there that doesn't check function-calls for failure results, and you can yank the rug out from under such software with totally unpredictable (crash-and-burn) results.
Last edited by sundialsvcs; 03-29-2017 at 08:09 AM.
In case someone bump in to this thread with the same issue. If you need to clean up semaphores in HPUX, do ipcs -s. If the status of the KEY is 0x0000000, then you can remove it.
e.g.
s 21315364 0x00000000 --ra------- hpsmh hpsmh <- This is unused semaphore and can safely remove.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.