Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

vmstat provides a counter cs for context switch. As this explains, the context switch can be from one process to another , kernel to user or due to a interrupt being fired. Does the cs give a total of this?If so, is there a way I can get an individual output

share|improve this question
What OS are you running ? – jlliagre Apr 29 '11 at 16:03
up vote 1 down vote accepted

Vmstat cs column is displaying, at least on Solaris, voluntary context switches, i.e. those happening when a process (thread really) is releasing the CPU because it has nothing else to do with it, for example waiting for some external event like a pending I/O to finish.

If you want to display involuntary context switches, you can use the mpstat command an look at its icsw column. Here are displayed context switches due to a process being interrupted/preempted because something with a bigger priority requires the CPU.

share|improve this answer

I think it may be OS-dependent. On AIX 6.1 you have (

"(cs is) Number of context switches per second observed in the interval. The physical CPU resource is subdivided into logical time slices of 10 milliseconds each. Assuming a thread is scheduled for execution, it will run until its time slice expires, until it is preempted, or until it voluntarily gives up control of the CPU. When another thread is given control of the CPU, the context or working environment of the previous thread must be saved and the context of the current thread must be loaded. The operating system has a very efficient context switching procedure, so each switch is inexpensive in terms of resources. Any significant increase in context switches, such as when cs is a lot higher than the disk I/O and network packet rate, should be cause for further investigation."

If you have sources of the vmstat on your system you may look inside and try to find out what it does.

share|improve this answer

For Linux, on kernels 2.6.23 and later you can get voluntary and involuntary context switches broken down by process with the command

pidstat -w

share|improve this answer
The 3.6 kernels only go up to you mean another version of kernel? – mdpc Feb 20 '13 at 21:16
Doh, thanks mdpc - it's actually 2.6.23 (corrected above). – justincc Apr 6 '13 at 1:53

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.