0

Is there any Linux command to get various information like context switches of a process? Any solution other than ps will be appreciated.

Jeff Schaller
  • 66,199
  • 35
  • 114
  • 250
al mamun
  • 123
  • 4
  • 13

1 Answers1

2

A context switch counters are in /proc/$$/status:

As an example:

voluntary_ctxt_switches: 230 nonvoluntary_ctxt_switches: 35

You can get this easily by doing something similar to:

$ grep ctxt /proc/1234/status

Ed Neville
  • 1,330
  • 10
  • 11
  • Interesting. I tried on few pid but they have no ctxt value. Will try on more pid. There is another command (#command pid) which shows useful information (context switch is one of them) just like the stat (#stat filename) command. It was a very nice utility which i forgot :( – al mamun Feb 21 '17 at 21:20
  • If you want rolling stats, look at pidstat -w 1 – Ed Neville May 20 '18 at 06:47