Sunday, March 27, 2011

libc interface v.s. system call

啥是System Call

$man 2 intro
INTRO(2)                                                Linux Programmer's Manual                                               INTRO(2)

NAME
       intro - Introduction to system calls

DESCRIPTION
       Section  2 of the manual describes the Linux system calls.  A system call is an entry point into the Linux kernel.  Usually, sys‐
       tem calls are not invoked directly: instead, most system calls have corresponding C library wrapper functions which  perform  the
       steps  required (e.g., trapping to kernel mode) in order to invoke the system call.  Thus, making a system call looks the same as
       invoking a normal library function.


每个system call都有一个number在<syscall.h>中. system call列表在Linux Kernel Source的arch/i386/kernel/entry.S中.

strace: 跟踪一个程序, 输出程序执行过程中所调用的system call

$strace ls 
execve("/bin/ls", ["ls"], [/* 25 vars */]) = 0
brk(0)                                  = 0x25b3000
access("/etc/ld.so.nohwcap", F_OK)      = -1 ENOENT (No such file or directory)
mmap(NULL, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f7c0f616000
access("/etc/ld.so.preload", R_OK)      = -1 ENOENT (No such file or directory)
open("/etc/ld.so.cache", O_RDONLY)      = 3
fstat(3, {st_mode=S_IFREG|0644, st_size=144586, ...}) = 0
...

System Call Reference

No comments: