LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   What is the impact of clearing all semaphore (https://www.linuxquestions.org/questions/linux-newbie-8/what-is-the-impact-of-clearing-all-semaphore-4175602632/)

packets 03-27-2017 10:10 AM

What is the impact of clearing all semaphore
 
Hi All,

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?

sundialsvcs 03-27-2017 10:20 AM

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? :tisk:

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.

packets 03-27-2017 10:34 AM

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.

rtmistler 03-27-2017 11:46 AM

Quote:

Originally Posted by packets (Post 5688841)
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?

sundialsvcs 03-28-2017 08:13 AM

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.

rtmistler 03-28-2017 08:16 AM

Quote:

Originally Posted by sundialsvcs (Post 5689221)
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.

packets 03-28-2017 08:30 PM

Here is sample link http://stackoverflow.com/questions/2...hores-on-linux

All reply on the post is to clear ALL semaphores. Not a single comment tell not to remove all semaphores.

rtmistler 03-28-2017 10:14 PM

That's a school assignment, not something you do as part of a system normally.

packets 03-28-2017 11:02 PM

Ok. So bottom line is remove only unused semaphores.

JJJCR 03-28-2017 11:18 PM

check out link below, on how to clear unused semaphores:

http://www.unix.com/aix/74632-how-cl...semaphore.html

or this link:>https://www.mkssoftware.com/docs/man1/ipcrm.1.asp

sundialsvcs 03-29-2017 08:07 AM

See also: Semaphore leftovers on Linux machine at SuperUser.Com.

And Delete all shared memory and semaphores on Linux at StackOverflow.Com.

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.

packets 05-10-2017 08:35 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.


All times are GMT -5. The time now is 10:43 AM.