SLIDE 18 CS3224 Chapter One 9/14/09 Sterling 18
9/14/09 Sterling - CS3224 35
System Calls
– Programmer’s view of the OS. – Provides safe interface between user code and kernel services. – Provided through a hardware instruction (usually referred to as TRAP) to switch modes and simultaneously transfer control.
– Process management:
- pid = fork()
- s = execve(name, argv, environp)
- pid = waitpid(pid, &statloc, options)
- exit(status)
– Directory management: mkdir, rmdir, link, unlink, mount, umount.
9/14/09 Sterling - CS3224 36
System Calls
How does one work? E.g. read.
– Call the “read” library function.
- read(from_file_descriptor, into_buffer, size)
- This is user level code that is linked into your program.
- Arguments to the function are put on the stack.
– The read function sets a code (on the stack or in a register) – Execute “Trap” instruction. – Hardware
- picks up new address from the interrupt table for the trap handler
- automatically jumps to that routine.
- switches to kernel mode (!!)
– Set up the “appropriate” environment, including stack. Identify which system call was intended and jump to the appropriate routine. – Return from the trap. That switches mode back to user and goes back to the “read function”. – Return from the read function to the user’s program.