diff --git a/content/notes/14-processes-and-system-calls.md b/content/notes/14-processes-and-system-calls.md index ada668424..e3f999804 100644 --- a/content/notes/14-processes-and-system-calls.md +++ b/content/notes/14-processes-and-system-calls.md @@ -42,4 +42,69 @@ system program types include., also runs in user space ## system calls +processes issue requests to the kernel by making system calls + +![system call diagram|300](https://i.imgur.com/GAktF7t.png) + +they are requesets to the OS kernel made through interrupt handlers + +the set of system calls is termed the programmer interface to OS + +System calls in xv6 +- fork() Create a new process +- exit() Terminate the current process +- wait() Wait for a child process to exit +- kill(pid) Terminate a process identified with pid +- getpid() Return the ID number of the current process +- sleep(n) Put the current process into sleep for n seconds +- exec(filename, *argv) Load a file named filename and execute it with arguments in argv +- sbrk(n) Update the process memory space by n bytes +- open(filename, flags) Open a file named filename with flags indicating read/write +- read(fd, buf, n) Read n bytes from an open file fd into buf +- write(fd, buf, n) Write n bytes from buf to an open file fd +- close(fd) Close the open file fd +- dup(fd) Duplicate the open file fd into another file +- descriptor (the return value) +- pipe(p) Create a pipe and return the file descriptors in p +- chdir(dirname) Change the current working directory of the process to dirname +- mkdir(dirname) Create a new directory dirname +- mknod(name, major, minor) Create a device file name with major and minor numbers +- fstat(fd) Return status information about an open file fd +- link(f1, f2) Create another name f2 for the file f1 +- unlink(filename) Remove a file named filename + +## interrupts +### detecting interrupt +CPU hardware containes a wire called the interrupt requirest line + +when a cpu is running an instruction-execute cycle +- fetch instruction from memory and store it in instruction register +- decode/execute instruction + +an extra step is included +- sense the interrupt request line. +- it it has a signal, then respond to the interrupt + +### responding interrupt +when interrupt detected, CPU switches to kernel space, and a handler function provided by the OS is invoked +- the context of the current instructionis saved +- control is transferred to a fixed memory location holding an interrupt-handling routine +- when the routine is finished, it restores the context of the interrupted process + +the interrupt vector is an array of lications thta hold the addresses of these interrupt-handling routines. (usually held in low memory) + +this is hard to do +- how to restore context? +- nested handlers? + +### what causes them +generated by: +- errors: e.g., division by zero, invalid memory access +- I/O device signals:; e.g., completion of IO operation or arrival of network packet +- system calls (also called trap or soft interrupt) with special instruction (int or svc) + +a system call generates an interrupt and the OS transfers control to a system call handler + +### data structure of kernel process +