LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
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, 05:50 AM   #1
Juc1
Member
 
Registered: Sep 2011
Location: UK
Posts: 83

Rep: Reputation: 6
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:	25
Size:	127.6 KB
ID:	11114  
 
Old 10-31-2012, 06: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, 06:17 AM   #3
Juc1
Member
 
Registered: Sep 2011
Location: UK
Posts: 83

Original Poster
Rep: Reputation: 6
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 06:20 AM.
 
Old 10-31-2012, 06:18 AM   #4
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 21,152

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

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

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

Original Poster
Rep: Reputation: 6
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, 06:41 AM   #6
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 21,152

Rep: Reputation: 4125Reputation: 4125Reputation: 4125Reputation: 4125Reputation: 4125Reputation: 4125Reputation: 4125Reputation: 4125Reputation: 4125Reputation: 4125Reputation: 4125
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, 06:46 AM   #7
Juc1
Member
 
Registered: Sep 2011
Location: UK
Posts: 83

Original Poster
Rep: Reputation: 6
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, 08:12 AM   #8
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,415
Blog Entries: 55

Rep: Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600
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



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

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

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