05-Syscalls Sol
05-Syscalls Sol
Process
fnCall()
Process Process
fnCall() sysCall()
OS
7
Copyright ©: Nahrstedt, Angrave, Abdelzaher
l After the switch to kernel mode, the processor must save all of its
registers and dispatch execution to the proper kernel function, after
checking whether EAX is out of range. The system call we are looking
at is implemented in the sys_read function. The read finally performs
the data transfer and all the previous steps are unwound up to the
calling user function.
8
Copyright ©: Nahrstedt, Angrave, Abdelzaher
9
Examples of System Calls
n Examples
¡ getuid() //get the user ID
¡ fork() //create a child process
¡ execve() //executing a program
n Don’t mix system calls with standard library
calls See man syscalls
¡ Differences?
¡ Is printf() a system call?
¡ Is rand() a system call?
n 2: System Call
n 3: Library Call
Copyright ©: University of Illinois CS 241 Staff 11
Major System Calls
Process Management
pid = fork( ) Create a child process identical to the parent
File Management
Today
fd = open(file, how, ...) Open a file for reading, writing or both
n A file system
¡ A means to organize, retrieve, and
update data in persistent storage
¡ A hierarchical arrangement of directories
¡ Bookkeeping information (file metadata)
n File length, # bytes, modified timestamp, etc
n Unix file system
¡ Root file system starts with “/”
n Parameters:
¡ fd: file descriptor
¡ buf: buffer
¡ cnt: length of buffer
¡ lseek ¡ fseek
¡ When a system call fails, it usually returns -1 and sets the variable errno
to a value describing what went wrong. (These values can be found in
<errno.h>.) Many library functions do likewise.
¡ The function perror() serves to translate this error code into human-
readable form.
¡ Note that errno is undefined after a successful library call: this call may
well change this variable, even though it succeeds, for example because
it internally used some other library function that failed. Thus, if a failing
call is not immediately followed by a call to perror(), the value of errno
should be saved.