Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to monitor number of syscalls executed by kernel?

I need to monitor amount of system calls executed by Linux. I'm aware that vmstat has ability to show this for BSD and AIX systems, but for Linux it can't (according to man page).

Is there any counter in /proc? Or is there any other way to monitor it?

like image 232
Yuri Avatar asked Jan 06 '12 11:01

Yuri


People also ask

How do I check Syscalls?

To see the amount of time spent in each system call, use the -T (syscall-times) option.

How many system calls in Linux kernel?

There are 116 system calls; documentation for these can be found in the man pages. A system call is a request by a running task to the kernel to provide some sort of service on its behalf.

Which command can be used to check the system calls called by the program on a Linux system?

The ls command internally calls functions from system libraries (aka glibc) on Linux. These libraries invoke the system calls that do most of the work.

Are Syscalls in kernel space?

Since system calls are executed in kernel mode, they have access to kernel space and if pointers are not properly checked user applications might get read or write access to kernel space. For example, let's consider the case where such a check is not made for the read or write system calls.


1 Answers

I wrote a simple SystemTap script(based on syscalls_by_pid.stp). It produces output like this:

ProcessName          #SysCalls

munin-graph          38609 
munin-cron           8160  
fping                4502  
check_http_demo      2584  
check_nrpe           2045  
sh                   1836  
nagios               886   
sendmail             747   
smokeping            649   
check_http           571   
check_nt             376   
pcscd                216   
ping                 108   
check_ping           100   
crond                87    
stapio               69    
init                 56    
syslog-ng            27    
sshd                 17    
ntpd                 9     
hp-asrd              8     
hald-addon-stor      7     
automount            6     
httpd                4     
stap                 3     
flow-capture         2     
gam_server           2     

Total                61686

The script itself:

#! /usr/bin/env stap

#
# Print the system call count by process name in descending order.
#

global syscalls

probe begin {
  print ("Collecting data... Type Ctrl-C to exit and display results\n")
}

probe syscall.* {
  syscalls[execname()]++
}

probe end {
  printf ("%-20s %-s\n\n", "ProcessName", "#SysCalls")
  summary = 0
  foreach (procname in syscalls-) {
    printf("%-20s %-10d\n", procname, syscalls[procname])
    summary = summary + syscalls[procname]
  }
  printf ("\n%-20s %-d\n", "Total", summary)
}
like image 140
Yuri Avatar answered Nov 14 '22 23:11

Yuri