OS - Processes Flashcards
is “reading from disk” an example of an abstraction the os provides?
Yes! it is machine independent, easier and hiding unnecessary details
name what relates to user-mode,kernel mode and hardware: editors, system calls, compilers, shell, process management, I/O, file system, disks, CPU. In addition, why the operating system is named also an “extended machine”?
User interface(shell, editors,compilers,etc) is where users can program. they ask the kernel for info using the library interface(open,close, fork, etc). the library interface is using the system call interface in order to move into “kernel mode” where we have UNIX operating system(process management, memory management, the file system, I/O, etc). the kernel mode then reads/writes the information from/to the Hardware(CPU,memory, disks, terminals, etc..) The OS is referred to as an “extended machine” because right from the hardware it gets extended to “kernel mode” and then to “user mode”
“Recipe”, “Baker”,”Ingredients”, “Baking the pie”. who is the process, program,processor and data?
Recipe = Program Baker = Processor Ingredients = data Baking the pie = Process
What are the goals of the OS regarding processes?
- interleave processes executions to maximize processor utilization 2. provide reasonable response time 3. allocate resources to processes. 4. support inter-process communication and synchronization.
when is a new process created?
- System initialization(userinit) 2. Exec 3. fork 4. batch job(?)
when does a process terminate?
- normal exit (voluntary) 2. error exit (voluntary) 3. fatal exit (involuntary) 4. killed by another process (involuntary)
what are the process states?
Running - using the CPU Runnable - temporarily stopped to let another process use the CPU Blocked - unable to run until some external(!) event happens.
can a process block itself? or run itself?
it can block itself, setting its state field to BLOCKED but it can’t run itself because the scheduler skips it as long it is in blocked state.
For what reason does a process become blocked?
- waits for some event(other process to end its job, etc) 2. waits for input from the kernel.
Scheduling: what is a single Blocked Queue?
the scheduler holds a “Ready Queue” for process that are ready to be executed. in addition it holds a “blocked queue” for processes that are waiting for some event.
Scheduling: what is a multiple Blocked Queue?
same idea as “Single Blocked Queue” just that here each blocked process is placed in a specific event queue.
what is a suspended process?
A process which has been moved from memory to disk
why is a context switch called a context switch?
because the processor operates in terms of context - registers, program counter, etc. when we switch processes we switch contexts
what happens in a context switch?
- we save the processor context and save it one the old process struct. 2. update old process state 3. move old process to appropriate queue. 4. select another process for execution(remove from queue) 5. update new process state 6. restore new process context
what does “fork” do?
it duplicate a process for a given program to create a new process, to perform other tasks: 1. parent check if process table is full, if not - it allocates a spot for the child 2. parent tries to allocate memory to child’s data and stack. 3. parent copies its code, data and stack to the child’s memory. 4. parent sets eax register of child to 0, so the “fork()” call returns 0 for the child 5. return pid of child.
what is exec for?
executing a new program; the program code is loaded to the process’ image: 1. fork() creates a new process 2. execvp replaces the process core image with that of another executable program
from shell(sh), which system calls occur in order to exec “ls”?
- fork() - create more process of sh 2. exec(“ls”,args) - use the new process for the new program - ls.
What is a signal? how is it generated?
It is a software interrupt. they are generated via: 1. keyboard - ctrl-C, ctrl-Z 2. kill syscall 3. command line - kill
who can a process send signals to?
To all process within its “process group”
What can a process do once receiving a signal?
- ignore it - not always 2. let the system take default action 3. catch it by process’ signal header
How defining a signal behavior is done?
by calling: signal(signum, [function|SIG_IGN,SIG_DFL])
how does a process receive a signal?
the kernel sets signal bits in the process struct upon receiving signals.
when is a “sigabrt” signal(core dump) received?
When there’s fault occurred in the program - usually due to an invalid pointer value(it is likely you are using an uninitialized pointer).
when is a “sigalrm” signal(alarm clock) received?
when sleep was called and time is up.
when is a “sigsegv” signal(segmentation fault) received?
Accessing memory that “does not belong to you”. that is, you are doing something wrong with memory - accessing memory that has already been freed, writing to a read-only portion of the memory, dereference a null pointer, dereference a pointer that ceased to exist(maybe was removed by the garbage collector) etc.
when is a “sigill” signal(illegal instruction) received?
when an attempt is made to execute an invalid, privileged, or ill-formed instruction
when does SIGCHILD is sent to parent?
upon child process termination
what happens if the parent terminates before the child?
the child is passed to the init process
what’s the name for a terminated child process for which its parent didn’t call wait()
A zombie! because it doesn’t get clean by the kernel via “wait()” system call which is called by the parent. that is, it still holds a process table entry.
what does a process control block hold? and what from that is moved to the Thread control block?
PCB: code, data, files, registers, user stack and kernel stack. TCB: registers, user stack and kernel stack.
what are the fields of a thread struct?
context trapframe kstack state
Why is a thread the basic unit for the CPU?
Because it holds all that CPU needs for running commands: program counter; register set; stack space
What are the benefits of threads?
- less time to create(vs process) 2. less time to terminate 3. less time to switch between threads within the same process 4. threads within the same process share memory and files -> they can communicate without invoking the kernel!
Does suspending a process means suspending all of its threads?
of course! all threads share the same PTE .
In a thread based system, what happens if fork() is called?
Only thread calling fork is duplicated.
what are the difference between User-Level Threads to Kernel Level Threads?
User-Level Threads: all management is done by the user. that is, the kernel is not aware of the existence of threads.
Advantages of User-Level-Threads
Thread switching does not require kernel mode privileges (faster) and the scheduler can be user specific(can be more efficient)
Disadvantages of User-Level-Threads
- A system call by a thread blocks the process. that means that if one threads reads from disk - all other threads are blocked. 2. Page fault - all other threads are blocked! 3. Time limit - cannot handle clock interrupts per thread. 4. stack growth fault - kernel is not aware of which thread’s stack caused the fault.
Kernel-Level Threads. How does it work?
- kernel maintains context information for the process and the threads. 2. kernel can schedule different threads of the same process to different processors. 3. switching between threads requires the kernel
What is the gain of using a multi-core?
Pipelining permits instruction-level parallelism. Multi-core permits both ILP and Thread-Level-Parallelism on same CPU.
What is a hardware threads?
It is an hardware in the core which appears to the OS as a logical processor and if the scheduler is aware of HW threads it would be much more efficient. The core stores more registers and logic for much faster thread context switch. For instance, some chips contain 8 cores, each comprising 8 HW cores for a total of 64 concurrent threads!
A system call can be roughly grouped into five major categories. What are they?
- Process control
- File management(read/write)
- Device management(attach a device)
- Information maintainance(set time or date)
- Communications(send messages)
What is a trapframe
A backup of the process’ current execution state.