The ps
command reports the CPU usage of a process in seconds. If you want to get this information in milliseconds, you can look at the end of this answer.
ps
truncates the total CPU time used by the process to the nearest low second, so you can safely assume that the process you looked up (bash
in your case) had used less than one CPU second so far.
This is normal, because bash
does not do any number crunching stuff to spend too many CPU cycles. bash
simply reads commands from input and calls the relevant executable to do the job requested by the command.
bash
itself is not a "CPU bound" process. However, you can make bash
use some CPU time by running the following bash
command, waiting a few seconds and killing it using Ctrl+C:
while [[ true ]] ; do : ; done
After that, you can check once more the CPU time spent by bash
by running ps
again.
I have written a simple script to display the total CPU time used by a process in milliseconds. Actually, on most systems the clock ticks 100 times per second, so the accuracy of the output is in tens of milliseconds. You can call this script by passing a single parameter specifying the process ID of the process you are interested, e.g. it will be 494
in your question.
#!/bin/bash
usage="Usage: $(basename $0) pid"
case "$*" in
''|*[!0-9]*)
echo "$usage" 1>&2
exit 1
;;
* )
pid="$1"
;;
esac
read -r -a pinfo <<< $(cat "/proc/$pid/stat" 2>/dev/null)
if (( ${#pinfo[@]} == 0 )) ; then
echo -e "No proccess with PID : $pid" >&2
exit 2
fi
let clk_tck="$(getconf CLK_TCK)"
let utime="${pinfo[13]}"
let stime="${pinfo[14]}"
let cputime=(utime + stime)*1000/clk_tck
echo "PID : ${pinfo[0]}
Cmd : ${pinfo[1]}
CPU : $cputime msec"
bash
process is less that a second. (Or less than half a second, in case thatps
rounds to the nearest second.)bash
process is less that a second? Can you please expand?bash
simply reads commands from input and calls the relevant binary to do the job requested by the command.bash
itself is not a CPU bound process. However you can make bash use some CPU by running the following bash command, waiting a few seconds and killing it using Ctrl+C:while [[ true ]] ; do : ; done