poor economy forces cutbacks on cnn stock images
The poor economy causes for strange cutbacks at times. Looks like CNN is trying to save some money on stock photos.
Linux total cpu time used
The occasion might arise such that you’re interested in looking at the total cpu time used of a system since boot. How much time has the cpu spent total, not just a snapshot, in userspace, kernelspace, niced, idle, etc?
The answer lies in /proc/stat!
Exhibit A:
rwoodrum@frums:~$ head -5 /proc/stat
cpu 309822 39124 179438 29687177 65905 873 1703 0 0
cpu0 54749 10781 13377 7193512 14861 278 395 0 0
cpu1 83633 10168 52991 7583192 15939 245 580 0 0
cpu2 81541 8563 49969 7425401 16223 182 381 0 0
cpu3 89897 9611 63098 7485070 18880 168 345 0 0
The above output is from my Goobuntu machine at work which obviously has a four core processor.
The numbers represent the count of jiffies the cpu has spent performing instructions in the following areas from left to right:
- user: normal processes executing in user mode
- nice: niced processes executing in user mode
- system: processes executing in kernel mode
- idle: zzzzz
- iowait: waiting for i/o completion
- irq: servicing interrupts
- softirqs: servicing soft interrupts
- steal: time spent in other operating systems if running virtualized
- guest: time spent running a virtual cpu for another os under control of the linux kernel
Note that you may have fewer columns. Some of these statistics are available only in more recent kernels. The “guest” statistic, for example, is in 2.6.24+. See man 5 proc for more information.
Which begets the question: How long is a jiffy?
The answer to this question lies in the kernel headers for particular architectures. A jiffy is defined by the kernel constant HZ. Take a look:
rwoodrum@frums:/usr/src/linux-headers-2.6.24-gg22/include/asm-x86$ grep ‘#define HZ’ param.h
#define HZ 100
As one may guess from the variable name, a jiffy in this case is defined as 1/100th of a second - this is the case for most, but not all, architectures.
So let’s compare this to the uptime of the machine. Right after the view into /proc/stat, I also looked at the uptime of the machine:
rwoodrum@frums:~$ uptime
10:04:47 up 19:56, 3 users, load average: 0.02, 0.03, 0.00
So let’s look at the aggregate of all cores; the “cpu” line from the above output:
- user: 309822 / 100 == 3098s user
- niced: 391s
- system: 1794s
- idle: 296871s
- iowait: 659s
- irq: 9s
- softirq: 170s
- steal: 0s
- guest: 0s
Note that the idle time is a little more than 82 hours but the uptime is only about 20 hours. Why the discrepancy? Because there are four cores sitting idle.
The output of /proc/stat comes from the show_stat() function in fs/proc/proc_misc.c.