Avatar of sharingsunshine
sharingsunshineFlag for United States of America

asked on 

What jobs are running in Linux PID?

I have certain PID's that are consuming memory on my VPS server and I need to  find out the jobs or applications that are part of that PID.

I have used strace -p [PID] but there are too many lines of code and they repeat  themselves.

Is there a way to  find out what applications/jobs are running and consuming the resources.  If not, what other suggestions do you have?
LinuxApache Web ServerServer Software

Avatar of undefined
Last Comment
madunix
Avatar of Gary
Gary
Flag of Ireland image

In the terminal window enter

top

and press >

That will give you the in memory processes by highest usage down
Avatar of sharingsunshine
sharingsunshine
Flag of United States of America image

ASKER

I know about top.  I need to know the applications in the pid that top is showing consume the most resources.  I know the pid I need an application/job breakdown.
Avatar of Jan Bacher
Jan Bacher
Flag of United States of America image

Have you tried lsof?  You can pull up all files associated with a PID.

http://www.thegeekstuff.com/2012/08/lsof-command-examples/
ASKER CERTIFIED SOLUTION
Avatar of Gary
Gary
Flag of Ireland image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of sharingsunshine
sharingsunshine
Flag of United States of America image

ASKER

Thanks for that suggestion but there are so many files listed I don't know what applications or jobs they belong to.  That's why I need a list  of jobs/applications per pid.  Then I can determine if those jobs/applications should be running or not.
Avatar of Gerwin Jansen
Gerwin Jansen
Flag of Netherlands image

Try: pstree -p <PID>

Example:

[gerwin@localhost ~]$ pstree -p 1868
lxterminal(1868)─┬─bash(1870)───bash(14897)───bash(15240)───pstree(15559)
                 ├─bash(15329)───top(15550)
                 ├─gnome-pty-helpe(1869)
                 ├─{lxterminal}(1871)
                 └─{lxterminal}(1878)
[gerwin@localhost ~]$
Avatar of sharingsunshine
sharingsunshine
Flag of United States of America image

ASKER

ls -l /proc/{proc id}/fd

e.g.
ls -l /proc/123/fd

When I do the above I get the following:

 ls -l /proc/19678/fd
ls: cannot access /proc/19678/fd: No such file or directory
Avatar of Gary
Gary
Flag of Ireland image

That means the process is finished
Avatar of Jan Bacher
Jan Bacher
Flag of United States of America image

Well if all you want is the job name:

ps -Af | grep PID

where "PID" is the process id.
Avatar of sharingsunshine
sharingsunshine
Flag of United States of America image

ASKER

Gerwin,

I just get the hash symbol

# pstree -p 19678
#
Avatar of Gary
Gary
Flag of Ireland image

Exactly which program/process is it you are trying to debug?
Avatar of Gerwin Jansen
Gerwin Jansen
Flag of Netherlands image

Then you have a non-existing PID, you should find your PID with top (sorted on memory use), then use that PID for the pstree command.
Avatar of sharingsunshine
sharingsunshine
Flag of United States of America image

ASKER

I was trying to debug 19678 to find out the applications that are using that process.
Avatar of Jan Bacher
Jan Bacher
Flag of United States of America image

But is it still running:

ps -Af | grep 19678

ls -l /proc/19678

If both return nothing, then the process has terminated.
Avatar of Gary
Gary
Flag of Ireland image

Well from what you posted above that process doesn't exist.
Every new process will use what every process id is available - programs don't use the same process ID every time
Avatar of sharingsunshine
sharingsunshine
Flag of United States of America image

ASKER

running this command

ps -Af | grep 19678
root     28455 24704  0 16:08 pts/2    00:00:00 grep 19678

does that mean it is running.  I tried to use the -r trigger to show only running processes but I must not have the syntax correct.
Avatar of Jan Bacher
Jan Bacher
Flag of United States of America image

it means that it is not running.

when you do a ps with a grep, unless you also add a "don't show me my grep", you'll see your request in the output.
Avatar of Gary
Gary
Flag of Ireland image

There is nothing using that PID, first line should be the application using the PID
Avatar of sharingsunshine
sharingsunshine
Flag of United States of America image

ASKER

OK, then Is there a way to  find out what applications/jobs are running and consuming the resources.  If not, what other suggestions do you have?  Since looking at the PID won't work.
Avatar of Gary
Gary
Flag of Ireland image

You do the top command, find the program's pid and then use the ls command
Avatar of Jan Bacher
Jan Bacher
Flag of United States of America image

When I want know what is consuming resources, I start with top.
Avatar of Gerwin Jansen
Gerwin Jansen
Flag of Netherlands image

@sharingsunshine - To speed things up a bit: show us the output of top after you've pressed >

Paste these 2 lines:
(I'm showing a firefox process using the most memory on my system)

 PID USER      PR  NI    VIRT    RES    SHR S %CPU %MEM     TIME+ COMMAND                                                                          
 1912 gerwin    20   0  921960 306064  37596 R 13.2 29.8  38:34.48 firefox
Avatar of sharingsunshine
sharingsunshine
Flag of United States of America image

ASKER

PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND            
26449 apache    20   0 2106m 190m 149m S 56.3  5.1   1:51.52 /usr/sbin/httpd
Avatar of sharingsunshine
sharingsunshine
Flag of United States of America image

ASKER

but if the processes go away how can you debug them?
Avatar of Gary
Gary
Flag of Ireland image

So are you trying to trace a php file or something?

Using the following will list all files being used by that process

ls -l /proc/26449 /fd
Avatar of sharingsunshine
sharingsunshine
Flag of United States of America image

ASKER

could your syntax be wrong?  Because I did a grep on the pid and it exists

]# ps -Af | grep 2068
mysql     2068  1861  2 Nov07 ?        11:51:55 /usr/libexec/mysqld --basedir=/usr --datadir=/data/mysql --plugin-dir=/usr/lib64/mysql/plugin --user=mysql --log-error=/var/log/mysqld.log --pid-file=/var/run/mysqld/mysqld.pid --socket=/var/lib/mysql/mysql.sock
root     32091 24704  0 16:39 pts/2    00:00:00 grep 2068
# ls -l /proc/2068 /fd
ls: cannot access /fd: No such file or directory
/proc/2068:
SOLUTION
Avatar of Gerwin Jansen
Gerwin Jansen
Flag of Netherlands image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
Avatar of sharingsunshine
sharingsunshine
Flag of United States of America image

ASKER

i did them back to back not sure why the timestamp didn't get copied.
Avatar of Gerwin Jansen
Gerwin Jansen
Flag of Netherlands image

Your PID is 26449 not 2068 - where do you get that from?
SOLUTION
Avatar of Jan Bacher
Jan Bacher
Flag of United States of America image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
Avatar of Gary
Gary
Flag of Ireland image

Are these you're own sites on the server?
Avatar of sharingsunshine
sharingsunshine
Flag of United States of America image

ASKER

26449 was gone and 2068 came up on top so I grabbed it as quick as I could.

yes they are my own sites
Avatar of sharingsunshine
sharingsunshine
Flag of United States of America image

ASKER

Thanks for all your help.
Avatar of madunix
madunix

You can run the following command #ps -p


http://www.cyberciti.biz/tips/top-linux-monitoring-tools.html
Linux
Linux

Linux is a UNIX-like open source operating system with hundreds of distinct distributions, including: Fedora, openSUSE, Ubuntu, Debian, Slackware, Gentoo, CentOS, and Arch Linux. Linux is generally associated with web and database servers, but has become popular in many niche industries and applications.

71K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo