Help answer threads with 0 replies.
Go Back > Forums > Linux Forums > Linux - Server
User Name
Linux - Server This forum is for the discussion of Linux Software used in a server related context.


  Search this Thread
Old 01-23-2008, 09:28 AM   #1
Registered: Sep 2007
Posts: 47

Rep: Reputation: 15
how to flush unused semaphores, after killing server

In server code , have created and using semaphore, after the server process is killed the semaphore remains unused.

thought adding script to remove leftover semaphores, before starting service nacsd start, in /etc/init.d/nacsd

Is it better to flush all semaphores left out. through command,( or programatically -for which when killed thougth catching signal and semctl to remove, but cant catch kill -9 signal)
i'm trying with command to be used. with ipcrm -s , for which we need to get semkeys/ids

ipcs -s | grep "0x"

0x00000000 196608 root 0 1
0x00000000 229377 root 0 1
0x00000000 262146 root 0 1
0x00000000 294915 root 0 1
0x00000000 327684 root 0 1
0x00000000 360453 root 0 1

ipcs -s | grep "0x"| ipcrm -s * tried with this but does not work.

thanku in advance
Old 01-23-2008, 10:57 AM   #2
Senior Member
Registered: Oct 2003
Location: Northeastern Michigan, where Carhartt is a Designer Label
Distribution: Slackware 32- & 64-bit Stable
Posts: 3,541

Rep: Reputation: 1060Reputation: 1060Reputation: 1060Reputation: 1060Reputation: 1060Reputation: 1060Reputation: 1060Reputation: 1060
Well, the best thing is to, in your executive before it exits, clean up (remove) shared memory, message queues and semaphores but during development when you crash every so often that isn't always possible with a signal handler, sigh.

What I do is, after the fact, clean up with a shell program that gets the list of keys with ipcs then removes them with ipcrm, one at a time in a for loop (you know, get the shared memory segments, do those, get the message queues, do those, get the semaphores, do those). I've never figured out a clean way to do it otherwise. You do have to be careful, though, to not kill segments, queues or semaphores that are used by other programs; e.g., MySQL, Firefox and others that use IPCs. It might even be useful to record the keys in a log file when you allocate or create them (kind of like the PID file used by Apache, MySQL and other applications) then just run those through a loop to get rid of them when the executive dies... just a thought.

Best of luck with it.


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
Wireless connnection dropping if unused on Ubuntu Server Edition AMarkos Linux - Wireless Networking 1 11-14-2007 07:35 PM
MySQL killing the server michux Linux - Server 12 07-06-2007 08:02 PM
Recovering unused hd space: Server vshell Linux - Newbie 4 05-16-2006 04:53 PM
flush my server logs? mikz Linux - Security 1 03-14-2005 06:34 AM
killing X server (and some more) kulmis Linux - Newbie 3 09-02-2004 07:31 PM > Forums > Linux Forums > Linux - Server

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

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