LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This 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


Reply
  Search this Thread
Old 03-27-2017, 10:10 AM   #1
packets
Member
 
Registered: Oct 2005
Posts: 327

Rep: Reputation: 32
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?
 
Old 03-27-2017, 10:20 AM   #2
sundialsvcs
LQ Guru
 
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 9,139
Blog Entries: 4

Rep: Reputation: 3227Reputation: 3227Reputation: 3227Reputation: 3227Reputation: 3227Reputation: 3227Reputation: 3227Reputation: 3227Reputation: 3227Reputation: 3227Reputation: 3227
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.
 
Old 03-27-2017, 10:34 AM   #3
packets
Member
 
Registered: Oct 2005
Posts: 327

Original Poster
Rep: Reputation: 32
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.
 
Old 03-27-2017, 11:46 AM   #4
rtmistler
Moderator
 
Registered: Mar 2011
Location: USA
Distribution: MINT Debian, Angstrom, SUSE, Ubuntu, Debian
Posts: 9,314
Blog Entries: 13

Rep: Reputation: 4370Reputation: 4370Reputation: 4370Reputation: 4370Reputation: 4370Reputation: 4370Reputation: 4370Reputation: 4370Reputation: 4370Reputation: 4370Reputation: 4370
Quote:
Originally Posted by packets View Post
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?
 
Old 03-28-2017, 08:13 AM   #5
sundialsvcs
LQ Guru
 
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 9,139
Blog Entries: 4

Rep: Reputation: 3227Reputation: 3227Reputation: 3227Reputation: 3227Reputation: 3227Reputation: 3227Reputation: 3227Reputation: 3227Reputation: 3227Reputation: 3227Reputation: 3227
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.
 
Old 03-28-2017, 08:16 AM   #6
rtmistler
Moderator
 
Registered: Mar 2011
Location: USA
Distribution: MINT Debian, Angstrom, SUSE, Ubuntu, Debian
Posts: 9,314
Blog Entries: 13

Rep: Reputation: 4370Reputation: 4370Reputation: 4370Reputation: 4370Reputation: 4370Reputation: 4370Reputation: 4370Reputation: 4370Reputation: 4370Reputation: 4370Reputation: 4370
Quote:
Originally Posted by sundialsvcs View Post
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.
 
Old 03-28-2017, 08:30 PM   #7
packets
Member
 
Registered: Oct 2005
Posts: 327

Original Poster
Rep: Reputation: 32
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.
 
Old 03-28-2017, 10:14 PM   #8
rtmistler
Moderator
 
Registered: Mar 2011
Location: USA
Distribution: MINT Debian, Angstrom, SUSE, Ubuntu, Debian
Posts: 9,314
Blog Entries: 13

Rep: Reputation: 4370Reputation: 4370Reputation: 4370Reputation: 4370Reputation: 4370Reputation: 4370Reputation: 4370Reputation: 4370Reputation: 4370Reputation: 4370Reputation: 4370
That's a school assignment, not something you do as part of a system normally.
 
Old 03-28-2017, 11:02 PM   #9
packets
Member
 
Registered: Oct 2005
Posts: 327

Original Poster
Rep: Reputation: 32
Ok. So bottom line is remove only unused semaphores.
 
Old 03-28-2017, 11:18 PM   #10
JJJCR
Senior Member
 
Registered: Apr 2010
Posts: 1,852

Rep: Reputation: 337Reputation: 337Reputation: 337Reputation: 337
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

Last edited by JJJCR; 03-28-2017 at 11:24 PM. Reason: edit
 
Old 03-29-2017, 08:07 AM   #11
sundialsvcs
LQ Guru
 
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 9,139
Blog Entries: 4

Rep: Reputation: 3227Reputation: 3227Reputation: 3227Reputation: 3227Reputation: 3227Reputation: 3227Reputation: 3227Reputation: 3227Reputation: 3227Reputation: 3227Reputation: 3227
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.

Last edited by sundialsvcs; 03-29-2017 at 08:09 AM.
 
Old 05-10-2017, 08:35 AM   #12
packets
Member
 
Registered: Oct 2005
Posts: 327

Original Poster
Rep: Reputation: 32
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.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Semaphore atulkatrajkar Linux - Newbie 4 10-12-2010 12:56 PM
LXer: Open Source Impact on Software Innovation Outweighs Impact on ... LXer Syndicated Linux News 0 08-15-2006 01:54 PM
Semaphore tzzdvd Programming 1 05-24-2005 09:23 PM
semaphore beginner_84 Programming 5 08-25-2004 06:54 PM
about semaphore dummyagain Programming 1 11-11-2003 11:09 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 04:36 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration