?
Solved

What jobs are running in Linux PID?

Posted on 2014-11-25
35
Medium Priority
?
182 Views
Last Modified: 2014-11-29
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?
0
Comment
Question by:sharingsunshine
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 13
  • 9
  • 6
  • +2
35 Comments
 
LVL 58

Expert Comment

by:Gary
ID: 40465312
In the terminal window enter

top

and press >

That will give you the in memory processes by highest usage down
0
 

Author Comment

by:sharingsunshine
ID: 40465320
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.
0
 
LVL 29

Expert Comment

by:Jan Springer
ID: 40465357
Have you tried lsof?  You can pull up all files associated with a PID.

http://www.thegeekstuff.com/2012/08/lsof-command-examples/
0
Will your db performance match your db growth?

In Percona’s white paper “Performance at Scale: Keeping Your Database on Its Toes,” we take a high-level approach to what you need to think about when planning for database scalability.

 
LVL 58

Accepted Solution

by:
Gary earned 1400 total points
ID: 40465369
Detailed breakdown

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

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

Open in new window

0
 

Author Comment

by:sharingsunshine
ID: 40465379
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.
0
 
LVL 38

Expert Comment

by:Gerwin Jansen, EE MVE
ID: 40465382
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 ~]$
0
 

Author Comment

by:sharingsunshine
ID: 40465387
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
0
 
LVL 58

Expert Comment

by:Gary
ID: 40465390
That means the process is finished
0
 
LVL 29

Expert Comment

by:Jan Springer
ID: 40465391
Well if all you want is the job name:

ps -Af | grep PID

where "PID" is the process id.
0
 

Author Comment

by:sharingsunshine
ID: 40465397
Gerwin,

I just get the hash symbol

# pstree -p 19678
#
0
 
LVL 58

Expert Comment

by:Gary
ID: 40465401
Exactly which program/process is it you are trying to debug?
0
 
LVL 38

Expert Comment

by:Gerwin Jansen, EE MVE
ID: 40465429
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.
0
 

Author Comment

by:sharingsunshine
ID: 40465455
I was trying to debug 19678 to find out the applications that are using that process.
0
 
LVL 29

Expert Comment

by:Jan Springer
ID: 40465460
But is it still running:

ps -Af | grep 19678

ls -l /proc/19678

If both return nothing, then the process has terminated.
0
 
LVL 58

Expert Comment

by:Gary
ID: 40465464
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
0
 

Author Comment

by:sharingsunshine
ID: 40465483
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.
0
 
LVL 29

Expert Comment

by:Jan Springer
ID: 40465490
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.
0
 
LVL 58

Expert Comment

by:Gary
ID: 40465491
There is nothing using that PID, first line should be the application using the PID
0
 

Author Comment

by:sharingsunshine
ID: 40465500
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.
0
 
LVL 58

Expert Comment

by:Gary
ID: 40465504
You do the top command, find the program's pid and then use the ls command
0
 
LVL 29

Expert Comment

by:Jan Springer
ID: 40465507
When I want know what is consuming resources, I start with top.
0
 
LVL 38

Expert Comment

by:Gerwin Jansen, EE MVE
ID: 40465516
@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
0
 

Author Comment

by:sharingsunshine
ID: 40465530
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
0
 

Author Comment

by:sharingsunshine
ID: 40465531
but if the processes go away how can you debug them?
0
 
LVL 58

Expert Comment

by:Gary
ID: 40465536
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
0
 

Author Comment

by:sharingsunshine
ID: 40465559
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:
0
 
LVL 38

Assisted Solution

by:Gerwin Jansen, EE MVE
Gerwin Jansen, EE MVE earned 200 total points
ID: 40465560
Or: pstree -p 26449
0
 

Author Comment

by:sharingsunshine
ID: 40465561
i did them back to back not sure why the timestamp didn't get copied.
0
 
LVL 38

Expert Comment

by:Gerwin Jansen, EE MVE
ID: 40465564
Your PID is 26449 not 2068 - where do you get that from?
0
 
LVL 29

Assisted Solution

by:Jan Springer
Jan Springer earned 400 total points
ID: 40465577
also, there isn't a space in the string:

ls -l /proc/2068/fd
0
 
LVL 58

Expert Comment

by:Gary
ID: 40465579
Are these you're own sites on the server?
0
 

Author Comment

by:sharingsunshine
ID: 40465593
26449 was gone and 2068 came up on top so I grabbed it as quick as I could.

yes they are my own sites
0
 

Author Comment

by:sharingsunshine
ID: 40465599
Thanks for all your help.
0
 
LVL 25

Expert Comment

by:madunix
ID: 40465604
You can run the following command #ps -p


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

Featured Post

Docker-Compose to Simplify Multi-Container Builds

Our veteran DevOps Author takes you through how to build a multi-container environment, managed with a single utility in order to simplify your deployments.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If your site has a few sections that need to be secure when data is transmitted between the server and local computer, such as a /order/ section for ordering or /customer/ which contains customer data, etc it would of course be recommended to secure…
Determining the an SCCM package name from the Package ID
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial
Suggested Courses
Course of the Month11 days, 22 hours left to enroll

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question