Why is the TIME 00:00:00 for bash process in ps command

While running the ps command, the output is as follows :

 PID TTY TIME CMD 494 pts/0 00:00:00 ps
29487 pts/0 00:00:00 bash
32617 pts/0 00:00:02 gedit

Why is the TIME 00:00:00 for bash? According to GeeksforGeeks, the explanation is as follows :

It is nothing but the total accumulated CPU utilization time for any process and 00:00:00 indicates no CPU time has been given by the kernel till now. In above example we found that, for bash no CPU time has been given.

Does someone has a better explanation ?

4

1 Answer

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"

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like