Skip to content

Instantly share code, notes, and snippets.

View shardulbee's full-sized avatar
🎯
Learning

Shardul Baral shardulbee

🎯
Learning
View GitHub Profile
let divisible n m = match n mod m with 0 -> true | _ -> false
let crackle_pop n =
let n_is_divisible_by = divisible n in
match (n_is_divisible_by 3, n_is_divisible_by 5) with
| true, true -> "CracklePop"
| true, _ -> "Crackle"
| _, true -> "Pop"
| _ -> string_of_int n

Processes

  • abstraction of running program
  • supports ability to have psuedo-concurrent operation
    • In a uniprogramming model, no notion of a process is needed, because you only have one at all times

Key elements of a process

  • program counter
  • registers

System Calls

  • The interface between user programs and the operating system is primarily about dealing with abstractions

  • a syscall library is provided in many languages to make system calls from the language

  • making a system call is a special type of procedure call except that syscalls enter kernel while procedure calls do not

    • procedure library in C executes some built-in api function, which traps to kernel with the specified params
  • TRAP instruction jumps to a fixed address, then this piece of code examines the syscall number and dispatches to the appropriate syscall handler (via id-handler indexed table)

  • Once syscall is completed its work, control might be returned to the user space procedure, and the stack is cleaned up

  • N.B. If the syscall is blocking, it will not return control to the user space procedure! ex. is a keyboard watiing for input

Practice Questions - Part 1

  1. How is a system call different from a function call?
  • A system call executes a piece of code in the kernel (protected) portion of the OS. A function call executes a piece of code in the user portion of the OS.
  1. How is system call processing different from interrupt servicing?
  • The OS processes system calls from the user while the OS processes interrupts from hardware or other processes in the OS
#include <stdio.h>
#include <unistd.h>
#include <sys/wait.h>
#include <fcntl.h>
int main() {
int pipefd[2];
pipe(pipefd);