SystemCall.md (1679B)
1 # System Call (syscall) 2 3 **Source:** CS 6200 4 5 **Chapter:** P1L2 6 7 **Definition:** A system call is performed by a user mode process to interface directly with the operating system. 8 9 ## Details 10 11 An operating system exports a set of system call operations that can be invoked by user mode processes. These (often) include opening of files, sending data over a socket, and allocating memory. 12 13 To make a system call: 14 15 - Write arguments 16 - These can be passed directly to the system call (register) or indirectly by specifying an address 17 - Save relevant data to well-defined location 18 - Allows OS to determine which arguments, how many, and where they are based on the system call number 19 - Make system call 20 21 ### Performance 22 23 At 2GHz there is ~50-100ns of latency imposed by the whole process. Additionally, this also impacts the hardware cache because there will probably be cache eviction during the context swap. 24 25 ### Modes 26 27 - Synchronous mode 28 - The process waits until the system call completes before continuing execution 29 - Asynchronous mode 30 31 ## Flow 32 33 ```mermaid 34 35 --- 36 title: System call flowchart 37 --- 38 39 stateDiagram-v2 40 direction LR 41 42 state UserProcess{ 43 A:User Process Executing 44 B:Calls system call 45 C:Returns from system call 46 } 47 48 state Kernel{ 49 D: Execute system call 50 } 51 52 A --> B 53 B --> D : trap mode bit = 0 54 D --> C : return mode bit = 1 55 56 ``` 57 58 NOTE: Kernel (privileged) mode is denoted with mode bit = 0. 59 60 ## System call definitions 61 62 ### Linux 64bit 63 64 - kill 65 - send a signal to a process 66 - setgid 67 - set group id for a process 68 - mount 69 - mount a file system 70 - sysctl 71 - read / write system parameters