LinuxQuestions.org
Review your favorite Linux distribution.
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 05-07-2007, 05:09 AM   #1
turalo
Member
 
Registered: Sep 2005
Location: NL
Distribution: linux, windows,
Posts: 108

Rep: Reputation: 16
Help needed 1 command line.


Hi guys, I need help creating one simple command,

what I want to do is kill all httpd procceses at once,
so if I do "ps -ef|grep httpd" I get 5 or 6 httpd proccesses

I want to kill them all, so all other processes stay, only httpd goes away, normaly if you do one by one you can use the pid , but I want to do it in one command.
like for example :
"ps -ef|grep httpd|kill -9 httpd but this does not works"

Please help.
 
Old 05-07-2007, 05:21 AM   #2
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389
Hi,

Something like this:

ps -ef | grep httpd | awk '{ print $2 }' | xargs kill

The awk part is needed to print the pid (and only the pid), xargs in turn gives all the found pid's to kill.

But...... Why not stop httpd the 'normal' (apachectl -k stop) way?

Hope this helps.
 
Old 05-07-2007, 05:32 AM   #3
theYinYeti
Senior Member
 
Registered: Jul 2004
Location: France
Distribution: Arch Linux
Posts: 1,897

Rep: Reputation: 63
ps h -eo pid,comm | grep httpd | awk '{print $1}' | xargs kill
or
killall httpd

Yves.
 
Old 05-07-2007, 05:35 AM   #4
turalo
Member
 
Registered: Sep 2005
Location: NL
Distribution: linux, windows,
Posts: 108

Original Poster
Rep: Reputation: 16
I need only to kill the Sesions, not the whole httpd deamon, so I need to keep apache runing, but kill all active sessions. So the webserver needs to be accesable. if I do the command wich you give, than it will kill the whole webserver.
 
Old 05-07-2007, 07:11 AM   #5
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389
Hi,

If things are set up correctly, the master process runs as root and all the sessions as none root. If this is the case:

ps -ef | grep httpd | grep -v root | awk '{ print $2}' | xargs kill

Hope this helps.
 
Old 05-08-2007, 02:27 AM   #6
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.9, Centos 7.3
Posts: 17,374

Rep: Reputation: 2383Reputation: 2383Reputation: 2383Reputation: 2383Reputation: 2383Reputation: 2383Reputation: 2383Reputation: 2383Reputation: 2383Reputation: 2383Reputation: 2383
You should use the apachectl cmd, it's designed to shutdown/start apache cleanly and correctly.
There's usually no pt trying to only kill the sessions, as Apache will automatically fork off new sessions to replace the dead ones.
You need to explain why you are trying to do this...
 
  


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
fat32 mounting help. unable to mount. correct command line needed smithy1010 Linux - Hardware 1 05-13-2006 06:33 AM
Command Line e-mail client w/Authentication Needed!! rootking Linux - Software 8 12-04-2005 07:00 PM
command line help needed mykrob Linux - Software 5 10-08-2004 12:10 AM
Command to output file content line by line aznluvsmc Programming 2 09-12-2004 07:45 PM
linux scripting help needed read from file line by line exc commands each line read atokad Programming 4 12-26-2003 10:24 PM

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

All times are GMT -5. The time now is 02:19 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration