LinuxQuestions.org
Share your knowledge at the LQ Wiki.
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 10-31-2012, 06:50 AM   #1
Juc1
Member
 
Registered: Sep 2011
Location: UK
Posts: 78

Rep: Reputation: 0
Identify process from PID


Hi all,

My 'top' command below catches my Debian 5 VPS jumping from low average load to high average load with about 6 processes using 100% of the CPU (causing the websites to fail for about 15 minutes or until I restart the VPS). Can I identify what these processes are from their PID? Or would the apache logs be more helpful?

Thank you
Attached Thumbnails
Click image for larger version

Name:	top.jpg
Views:	20
Size:	127.6 KB
ID:	11114  
 
Old 10-31-2012, 07:03 AM   #2
shivaa
Senior Member
 
Registered: Jul 2012
Location: Grenoble, Fr.
Distribution: Sun Solaris, RHEL, Ubuntu, Debian 6.0
Posts: 1,800
Blog Entries: 4

Rep: Reputation: 286Reputation: 286Reputation: 286
You can close apache2 processes, using:-
ps -ef | grep apache2
And then,
Quote:
kill -9 <PIDs>
killall -9 apache2
Then if needed, you can restart apache service.
 
Old 10-31-2012, 07:17 AM   #3
Juc1
Member
 
Registered: Sep 2011
Location: UK
Posts: 78

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by shivaa View Post
You can close apache2 processes, using:-
ps -ef | grep apache2
And then,

Then if needed, you can restart apache service.
Ok thanks but I meant to say that this happens regularly every day - so I am trying to work out the cause.

Last edited by Juc1; 10-31-2012 at 07:20 AM.
 
Old 10-31-2012, 07:18 AM   #4
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 14,833

Rep: Reputation: 1820Reputation: 1820Reputation: 1820Reputation: 1820Reputation: 1820Reputation: 1820Reputation: 1820Reputation: 1820Reputation: 1820Reputation: 1820Reputation: 1820
"cat /proc/<pid>/cmdline".

... or just run top with the "-c" switch.

Last edited by syg00; 10-31-2012 at 07:21 AM. Reason: ... or
 
Old 10-31-2012, 07:31 AM   #5
Juc1
Member
 
Registered: Sep 2011
Location: UK
Posts: 78

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by syg00 View Post
"cat /proc/<pid>/cmdline".
Am I doing something wrong...

Code:
$ cat /proc/18272/cmdline
cat: /proc/18272/cmdline: No such file or directory
$

Thanks
 
Old 10-31-2012, 07:41 AM   #6
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 14,833

Rep: Reputation: 1820Reputation: 1820Reputation: 1820Reputation: 1820Reputation: 1820Reputation: 1820Reputation: 1820Reputation: 1820Reputation: 1820Reputation: 1820Reputation: 1820
Depending on the process, you may need to be root, but more likely the process has already terminated - the /proc/<pid>/... "files" only exist whilst that process is active.
 
Old 10-31-2012, 07:46 AM   #7
Juc1
Member
 
Registered: Sep 2011
Location: UK
Posts: 78

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by syg00 View Post
Depending on the process, you may need to be root, but more likely the process has already terminated - the /proc/<pid>/... "files" only exist whilst that process is active.
Ok thanks - probably terminated because I restarted the VPS. So does a process get a consistent PID or might the PID vary from one day to another?

Thanks
 
Old 10-31-2012, 09:12 AM   #8
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,331
Blog Entries: 55

Rep: Reputation: 3529Reputation: 3529Reputation: 3529Reputation: 3529Reputation: 3529Reputation: 3529Reputation: 3529Reputation: 3529Reputation: 3529Reputation: 3529Reputation: 3529
Quote:
Originally Posted by shivaa View Post
ps -ef | grep apache2
Quote:
kill -9 <PIDs>
You mean pgrep apache2 or for sending a signal and allowing processes to close file descriptors:
Code:
pkill -15 apache2; sleep 10s; pkill -9 apache2

Quote:
Originally Posted by shivaa View Post
You can close apache2 processes
Killing processes may alleviate the stress the system is under but without (pointing to performing) proper analysis it's like treating symptoms instead of addressing the root cause: not that effective.


Quote:
Originally Posted by Juc1 View Post
Or would the apache logs be more helpful?
Depending on how your machines specs (RAM and other bottlenecks), how access is regulated (like firewall request limiting), how your web server is configured (like stock with all unnecessary modules loaded), what it runs (any interpreter-based Off The Shelf application, homebrewn code, etc, etc) and their dependencies / configuration, web server configuration and access + error log files should be the first things to check. You can also look at a current process with 'strace'. First select the Process Id:
Code:
pgrep apache2
and then
Code:
strace -o/path/to/strace.log -v [PID]
when you think you've got sufficient nfo kill the process with CTRL+C and then read "/path/to/strace.log" for clues.
*Also note that collecting system statistics over time, running any SAR like Atop, Dstat or Collectl, may give a better picture of what happens and when making it easier to search logs for clues.


Quote:
Originally Posted by Juc1 View Post
probably terminated because I restarted the VPS. So does a process get a consistent PID or might the PID vary from one day to another?
Restarting a service might help but restarting your VPS is quite drastic as you loose information that may help diagnosing the problem and it isn't how Linux should be handled. And PIDs are assigned sequentially BTW. With this:
Code:
\ps axfo pid,ppid,pgid,uid,cmd --sort=pid
you'll see all processes sorted by PID and this:
Code:
\ps -C apache2 fo pid,ppid,pgid,uid,cmd --sort=pid
confines your view to only Apache2 processes.
 
  


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] How to save the pid of a process at the time of process startup jhonnappier2007 Linux - Newbie 13 11-21-2011 12:54 AM
Two ways you can identify the PID number of your login shell. michael mc hugh Linux - Newbie 16 11-04-2010 07:08 PM
How to get the PID of the process giving kill signal to a process? hariprd Programming 2 11-27-2008 04:10 AM
one line identify and kill PID (scriptable) r00tb33r Linux - Software 3 02-06-2008 05:52 PM


All times are GMT -5. The time now is 07:31 PM.

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