Craig Small: Manually calculating process times
Most of the time you can trust the times you see in programs such as ps and top within Linux, but there are those other times where you just want to check what is going on.
First up, if you're using a FreeBSD system and the procps Linux tools, you're out of luck because a lot of the procfs is broken. You're almost guaranteed to get wierd results.
Jiffies and Hertz
The first thing to find is your jiffies. This is the number of clock ticks per second. There are two main ways of doing it.
The first, and more difficult way is to add up the cpu numbers in /proc/stat, divide it by the first number in /proc/uptime and divide it by the number of cpus.
My cpu line in /proc/stat looks like:
and my /proc/uptime is:
I've got 2 cpus on this system so the calculation is:
The second way is to use getconf, with the command "getconf CLK_TCK" which again on this system gives you 100.
We call this value "Hertz" and is usually 100 or 1024 though for some architectures it is other values.
Start Time
For each process the procfs has the start time, but it is expressed as the number of jiffes since the computer was booted. If we want to know the real "wall clock" time a process is started we have to start with number of seconds since epoch (for example using the time() function) subtract the number of seconds since the computer was booted and add the process start time from procfs.
The seconds since boot is the first value in /proc/uptime:
The 22nd item in a procfs PID stat file is the number of jiffes since boot when the process started. We have to divide it by Hertz to calculate the number of seconds.
27139 (bash) S 11942 27139 27139 34821 5200 4202496 5500 25537 0 14 40 16 18 15 20 0 1 0 69446639 23433216 1378 18446744073709551615 4194304 5082140 14073724008 6512 140737240085456 140127945249678 0 65536 3686404 1266761467 0 0 0 17 1 0 0 0 0 0
To get the start time, take the current time, subtract the boot time and add the process start time.
Unless you are very quick, you will have to take a few seconds off because the time() function will be now, while the values from the proc files will be a few seconds earlier as it takes time for you to cut and paste.

First up, if you're using a FreeBSD system and the procps Linux tools, you're out of luck because a lot of the procfs is broken. You're almost guaranteed to get wierd results.
Jiffies and Hertz
The first thing to find is your jiffies. This is the number of clock ticks per second. There are two main ways of doing it.
The first, and more difficult way is to add up the cpu numbers in /proc/stat, divide it by the first number in /proc/uptime and divide it by the number of cpus.
My cpu line in /proc/stat looks like:
cpu 1267430 145826 552700 137029699 905086 8295 17885 0 0
and my /proc/uptime is:
695317.99 1370303.58
I've got 2 cpus on this system so the calculation is:
(1267430 + 145826 + 552700 + 137029699 + 905086 + 8295 + 17885 + 0 + 0 ) / 695317.99 / 2which equals 100.
The second way is to use getconf, with the command "getconf CLK_TCK" which again on this system gives you 100.
We call this value "Hertz" and is usually 100 or 1024 though for some architectures it is other values.
Start Time
For each process the procfs has the start time, but it is expressed as the number of jiffes since the computer was booted. If we want to know the real "wall clock" time a process is started we have to start with number of seconds since epoch (for example using the time() function) subtract the number of seconds since the computer was booted and add the process start time from procfs.
The seconds since boot is the first value in /proc/uptime:
696141.85 1371857.53
The 22nd item in a procfs PID stat file is the number of jiffes since boot when the process started. We have to divide it by Hertz to calculate the number of seconds.
27139 (bash) S 11942 27139 27139 34821 5200 4202496 5500 25537 0 14 40 16 18 15 20 0 1 0 69446639 23433216 1378 18446744073709551615 4194304 5082140 14073724008 6512 140737240085456 140127945249678 0 65536 3686404 1266761467 0 0 0 17 1 0 0 0 0 0
To get the start time, take the current time, subtract the boot time and add the process start time.
perl -e '$nowstr = localtime(time() - 696141.85 + 69446639 / 100); print $nowstr, "\n";
Mon Jul 12 22:20:07 2010
Unless you are very quick, you will have to take a few seconds off because the time() function will be now, while the values from the proc files will be a few seconds earlier as it takes time for you to cut and paste.

1
I have noticed that when I am reading, I cannot simultaneously understand spoken words. If someone speaks to me while I am reading, I can pay attention to their voice, or to the text, but not both. It s as if these two functions share the same cognitive facility, and this facility can only handle one task at a time. If someone is talking on the phone nearby, I find it very difficult to focus on reading (or writing). If I m having a conversation with someone about a document, I sometimes have to ask them to pause the conversation for a moment while I read.
This phenomenon isn t unique to me. In Richard Feynman s
Working on and for Debian for the whole millennium already it would had been hard to not notice Ubuntu through the times. Given that fixing bugs in the package is in the interest of all involved parties I started to get curious for the
Apropos of
Since I'm
Today I started to tell a friend about something from dinner the night
before. Except that she was at the dinner. And sitting at the same
table! Even when prompted, I couldn't really remember!
This does not warrant a blog post. Anybody who knows me well knows that
my memory for these kinds of more mundane details is pretty porous. This
kind of thing happens all the time.
I'm writing this so that when I'm much older, and still forgetting
things all the time, folks can use this as a reference point before
concluding that senility is setting in.
I'm afraid that everyone else will forget my forgetfulness!
I had a constructive meeting with my Member of Parliament yesterday, in which he agreed to push




Bug-Squashing-Party in Munich
We are