top
Example of firefox. Find the PID:
ps -aux | grep -i firefox
Then you can use top -p pid
:
top -p 3845
ps
You can also use ps
command, firefox pid is 3845
$ ps -p 3845 -o %cpu,%mem,cmd
%CPU %MEM CMD
11.1 3.7 /usr/lib/firefox/firefox
I am not satisfied with the above mentioned commands, and I found something that you should be interested in.
Monit
sudo apt-get install monit -y
Edit the Monit Config File
sudo nano /etc/monit/monitrc
Enable the web interface
set httpd port 2812
# use address localhost # only accept connection from localhost
allow localhost # allow localhost to connect to the server and
# allow 192.168.1.0/255.255.255.0 # allow any host on 192.168.1.* subnet
allow admin:monit # require user 'admin' with password 'monit'
Checking process every 2 secons
## Start Monit in the background (run as a daemon):
set daemon 120 to only 2 # check process every 2 sec
Example Firefox
In the end copy paste the following command
check process firefox
matching "firefox"
Save and Exit
Check your syntax
Fix any problems found – it’s not too tough to figure out what’s going on.
sudo monit -t
Start (or restart) Monit
sudo service monit start
Visit the web interface
http://localhost:2812
if you’re running Ubuntu Desktop, or
Sign in with your admin:monit
credentials
Click on Firefox
Related:
You can also use these links for help and modify your process.
UPDATE
You can also configure an alert if firefox uses more than 250 MB of ram
check process firefox
matching "firefox"
if totalmem > 250.0 MB for 1 cycles then alert
You can also execute command
if totalmem > 250.0 MB for 1 cycles then exec "path to script"
You can also make a script of Notify-Send
/usr/bin/notify-send firefox "More Than 250 MB OF RAM"
Taken from Bash - Update terminal title by running a second command · U&L and slightly changed:
trap 'echo -ne "\033]2;$(history 1 | sed "s/^[0-9 ]* \+//")\007"' DEBUG
This (ab)uses the DEBUG
signal as a trigger to update the title with the last entry from your history, i.e. the last command you executed, via an XTerm Control Sequence. Add the line to your ~/.bashrc
to have the feature enabled in every new terminal window.
To print other command output alongside in the title, say the current directory with pwd
followed by ": " and the currently running command, I recommend using printf
as follows:
trap 'echo -ne "\033]2;$(printf "%s: %s" "$(pwd)" "$(history 1 | sed "s/^[0-9 ]* \+//")")\007"' DEBUG
Some terminal emulators allow you to specify a dynamic title and even give you the command name as an option so that you don't even need to fiddle around – I searched and found it in yakuake
's profile settings.
Best Answer
Add
time
before the command you want to measure. For example:time ls
.The output will look like:
Explanation on
real
,user
andsys
(fromman time
):real
: Elapsed real (wall clock) time used by the process, in seconds.user
: Total number of CPU-seconds that the process used directly (in user mode), in seconds.sys
: Total number of CPU-seconds used by the system on behalf of the process (in kernel mode), in seconds.