OS 03 Syscalls
OS 03 Syscalls
CS31202 / CS30002
Some slides borrowed from slides of Don Porter, Univ of North Carolina (UNC)
What are system calls?
• The mechanism used by an application program to
request service from the operating system
• So how does it work?
This lecture
• Resume a program
• Read the register contents back from memory to the CPU
System calls
Earlier days
• Originally, system calls issued using “int” instruction
Earlier days
• Originally, system calls issued using “int” instruction
• The system call handler routine was just an interrupt
handler
Earlier days
• Originally, system calls issued using “int” instruction
• The system call handler routine was just an interrupt
handler
• Like interrupts, system calls used to be arranged in a
table
Earlier days
• Originally, system calls issued using “int” instruction
• The system call handler routine was just an interrupt
handler
• Like interrupts, system calls used to be arranged in a
table
• http://man7.org/linux/man-pages/man2/read.2.html
Example of a system call API
• http://man7.org/linux/man-pages/man2/read.2.html
Functions we
write in HLL
(printf, scanf)
Lower level
standard C
library call
(read, write)
syscall
instruction
Types of system calls
(From silberschatz’s slides)
Types of System Calls
• Process control (e.g., fork(), exit(), wait() )
• create process, terminate process (fork, exit)
• end, abort
• load, execute
• get process attributes, set process attributes
• wait for time
• wait event, signal event
• allocate and free memory
• Dump memory if error
• Debugger for determining bugs, single step execution
• Locks for managing access to share data between
processes
Types of System Calls (Cont.)
• File management (e.g., open(), close(), read(), write())
• create file, delete file
• open, close file
• read, write, reposition
• get and set file attributes
• Device management (e.g., ioctl(), read(), write())
• request device, release device
• read, write, reposition
• get device attributes, set device attributes
• logically attach or detach devices
Types of System Calls (Cont.)
• Inter-Process Communications (e.g., pipe(),
semget(), semop(), shmget(), shmcat(), shmdt(),
shmctl(), signal(), kill())
• create, delete communication connection
• send, receive messages if message passing
model to host name or process name
• Shared-memory model create and gain access
to memory regions
• transfer status information
• attach and detach remote devices
Types of System Calls (Cont.)