How to see processes or resources used by an application

How to do things, solutions, recipes, tutorials
Post Reply
Message
Author
musher0
Posts: 14629
Joined: Mon 05 Jan 2009, 00:54
Location: Gatineau (Qc), Canada

How to see processes or resources used by an application

#1 Post by musher0 »

Hello all.

Here are various ways to see the processes or resources used by an application.

This can be useful for debugging a weird behavior in a program or simply out of
curiosity.

I am not including any screen shots, because by just typing the command in
console, you will have an illustration of what it does.

Let's say we have geany open. (But we can do this for any program.)

To find the resources geany is using, we can type:

Code: Select all

htop -p `pgrep geany`
-- `pgrep geany` gives htop the process ID number it needs to inform you on geany.
Typing < htop -p geany > by itself won't work.

Code: Select all

ps | grep geany
-- Typing < ps > by itself will provide you with an ultra long listing of everything
running on your Linux machine. We seldom need all that info; we usually want
something more focused, which is why we filter the info through < grep >.
Note: you can type < ps --help > to see the many possible parms for < ps >. But
the use with a pipe to grep gives more direct info about a program.

Code: Select all

pstree -p `pgrep geany`
-- again used with pgrep
-- info is similar to what < ps | grep geany > will give you, but with the process(es)
that called it, etc., in tree form.

~~~~~~~~~~

lsof is probably the most informative :
(The real one please; by comparison, the busybox cut-down version gives limited
info. May I suggest one of the pet archives on this page.

They all offer the complete lsof program. Some pet archives there are larger because
they also contain the docs for lsof. At the time of this writing, the lsof-4.89 offered
on that forum page is still the latest version.)

Code: Select all

lsof -c geany | more 
-- < | more > is used so we can see one screen of info at a time. The whole listing
is about 117 lines long.

If we want to limit the amount of info, we type this:

Code: Select all

lsof -c geany | grep -v -E "font|ttf|so|mo|locale|null|cache" | more 
Explanation of the grep exclusions:
-- font|ttf : exclude the fonts geany is using
-- so : exclude the libraries it is using
-- mo|locale : exclude any language files
-- null : exclude any process going to /dev/null
-- cache : exclude the cache(s) geany is using.

You can mix and match those exclusions, use one or two or three, etc., instead of
the whole bunch, depending on what you need to know.

By contrary, you can see what information lsof is including by default about geany
-- or any other program. lsof provides a great deal of info.

~~~~~~~~~~

The above tools provide a different angle as to what resources and processes are
being used by a program. Use the one that gives you the info you need to know.

If you know of other such tools, please mention them below for our benefit. Thanks.

IHTH. BFN.
Last edited by musher0 on Fri 22 Dec 2017, 05:42, edited 1 time in total.
musher0
~~~~~~~~~~
"You want it darker? We kill the flame." (L. Cohen)

phat7
Posts: 179
Joined: Fri 05 Jun 2015, 08:54

Re: How to see processes or resources used by an application

#2 Post by phat7 »

To find the resources geany is using, we can type:

Code: Select all

htop -c `pgrep geany`

Code: Select all

# htop -c `pgrep geany`
htop: invalid option -- 'c'

musher0
Posts: 14629
Joined: Mon 05 Jan 2009, 00:54
Location: Gatineau (Qc), Canada

Re: How to see processes or resources used by an application

#3 Post by musher0 »

phat7 wrote:
To find the resources geany is using, we can type:

Code: Select all

htop -c `pgrep geany`

Code: Select all

# htop -c `pgrep geany`
htop: invalid option -- 'c'
Sorry. Typo corrected above. That should be a "p".
Thanks for having noticed.
musher0
~~~~~~~~~~
"You want it darker? We kill the flame." (L. Cohen)

Post Reply