LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Server (https://www.linuxquestions.org/questions/linux-server-73/)
-   -   Best way to clear Locked Apache Semaphores with ipcrm? (https://www.linuxquestions.org/questions/linux-server-73/best-way-to-clear-locked-apache-semaphores-with-ipcrm-776204/)

Rudy 12-16-2009 04:21 PM

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

zordrak 12-17-2009 09:40 AM

Quote:

Originally Posted by Rudy (Post 3794315)
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 (Post 3794315)
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 (Post 3794315)
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 (Post 3794315)
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 (Post 3794315)
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 (Post 3794315)
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 (Post 3794315)
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.

Rudy 12-17-2009 10:47 AM

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?

zordrak 12-17-2009 11:05 AM

Quote:

Originally Posted by Rudy (Post 3795579)
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.


All times are GMT -5. The time now is 06:41 AM.