LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices


Reply
  Search this Thread
Old 12-16-2009, 04:21 PM   #1
Rudy
Member
 
Registered: Aug 2003
Location: United States
Distribution: Ubuntu 9.10, Red Hat
Posts: 49

Rep: Reputation: 15
Best way to clear Locked Apache Semaphores with ipcrm?


We tried restarting apache earlier today, and our semaphores were all locked up. So I ran the following command:
Code:
for i in 'ipcs -s | grep nobody | awk '{print $2}'` do ipcrm sem $i done
That didn't seem to do anything... just returned > every time I hit enter. I had to ctl-c to get back to the prompt.

Then I ran the script that our server support has run in the past when semaphores locked up:
Code:
ipcs -s | grep nobody | perl -e 'while () { @a=split(/\s+/); print `ipcrm sem $a[1]`}'
and I got the following for every loop:
Code:
deprecated usage: ipcrm {shm | msg | sem} id ...
usage: ipcrm [ [-q msqid] [-m shmid] [-s semid]
[-Q msgkey] [-M shmkey] [-S semkey] ... ]
Edit: I should clarify that I let this go on for some time, but it kept giving me this error message, so I finally ctl-c'd it to stop the process. Maybe it did work, and I just was impatient? See below...

So I have a few questions...
1) Is it safe to run ipcrm while apache is running?

2) Why is my hosting support using a deprecated script, and why did that seem to work anyway (although when I run ipcs -s | grep nobody, it seems that a ton of semaphores exist)?

In the past, we have always called our hosting company for support when this issue has arisen. But I feel more comfortable, I think, than the others in the office to do more and more of our server admin stuff. Since I've been here (for about 6 months now), I've started researching things that we can do on our own.

Anyway, in the past when they run the script above, I will run
Code:
ipcs -s | grep nobody
to see the difference, and after they clear the semaphores, very few are listed.

Today, after running both scripts above, I run ipcs -s | grep nobody, and I still see quite a few semaphores. Perhaps I didn't give the first script long enough to run, and that some of the semaphores were deleted, and that script is actually the one that fixed things?

Any ideas, comments, or solutions?

Thanks,
David

Last edited by Rudy; 12-16-2009 at 04:28 PM. Reason: Clarification
 
Old 12-17-2009, 09:40 AM   #2
zordrak
Member
 
Registered: Feb 2008
Distribution: Slackware
Posts: 595

Rep: Reputation: 116Reputation: 116
Quote:
Originally Posted by Rudy View Post
We tried restarting apache earlier today, and our semaphores were all locked up. So I ran the following command:
Code:
for i in 'ipcs -s | grep nobody | awk '{print $2}'` do ipcrm sem $i done
That didn't seem to do anything... just returned > every time I hit enter. I had to ctl-c to get back to the prompt.
That's because you used "`" only once. It was never closed. Try this:
Code:
for i in $(ipcs -s | grep nobody | awk '{print $2}'); do ipcrm sem $i; done
Quote:
Originally Posted by Rudy View Post
So I have a few questions...
1) Is it safe to run ipcrm while apache is running?
Yes. Run the command. Then restart Apache.

Quote:
Originally Posted by Rudy View Post
2) Why is my hosting support using a deprecated script, and why did that seem to work anyway (although when I run ipcs -s | grep nobody, it seems that a ton of semaphores exist)?
The script isn't deprecated it's just not giving ipcrm what it expects.. probably just broken implementation like the first example above, I haven't checked this one.

Quote:
Originally Posted by Rudy View Post
In the past, we have always called our hosting company for support when this issue has arisen. But I feel more comfortable, I think, than the others in the office to do more and more of our server admin stuff. Since I've been here (for about 6 months now), I've started researching things that we can do on our own.
If they know the answers, why not ask them? Best research there is.

Quote:
Originally Posted by Rudy View Post
Anyway, in the past when they run the script above, I will run
Code:
ipcs -s | grep nobody
to see the difference, and after they clear the semaphores, very few are listed.
Because they have cleared them..

Quote:
Originally Posted by Rudy View Post
Today, after running both scripts above, I run ipcs -s | grep nobody, and I still see quite a few semaphores.
Because you haven't cleared them..

Quote:
Originally Posted by Rudy View Post
Perhaps I didn't give the first script long enough to run, and that some of the semaphores were deleted, and that script is actually the one that fixed things?
No. See above.

Last edited by zordrak; 12-17-2009 at 09:46 AM.
 
Old 12-17-2009, 10:47 AM   #3
Rudy
Member
 
Registered: Aug 2003
Location: United States
Distribution: Ubuntu 9.10, Red Hat
Posts: 49

Original Poster
Rep: Reputation: 15
That was very helpful. Thank you.

We haven't been very pleased with our hosting company, and we are getting ready to purchase our own hardware. So knowing these things is good anyway.

Based on your answer, it seems to me that you're saying NONE of the semaphores were never cleared. So my question is, why was I able to start Apache after running these two scripts?

Last edited by Rudy; 12-17-2009 at 10:50 AM.
 
Old 12-17-2009, 11:05 AM   #4
zordrak
Member
 
Registered: Feb 2008
Distribution: Slackware
Posts: 595

Rep: Reputation: 116Reputation: 116
Quote:
Originally Posted by Rudy View Post
Based on your answer, it seems to me that you're saying NONE of the semaphores were never cleared. So my question is, why was I able to start Apache after running these two scripts?
The perl one probably cleared some and failed on others or something., no biggie.
 
  


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
apache semaphores izghitu Linux - Software 2 12-07-2008 07:35 AM
How to clear a std::string buff.clear()? lucky6969b Programming 3 03-17-2006 07:50 AM
how do i replace the clear "clear screen" with the cls command thefedexguy SUSE / openSUSE 2 12-02-2005 05:02 PM
Semaphores help mojozoox Programming 1 01-07-2004 08:41 AM
semaphores charles_sjc Linux - Software 2 12-06-2003 12:15 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Server

All times are GMT -5. The time now is 03:37 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