Download presentation
Presentation is loading. Please wait.
Published byArlene Rogers Modified over 8 years ago
1
spcl.inf.ethz.ch @spcl_eth S ALVATORE DI G IROLAMO (TA) Networks and Operating Systems: Exercise Session 1
2
spcl.inf.ethz.ch @spcl_eth About me: Name: Salvatore Di Girolamo Contact: digirols@inf.ethz.chdigirols@inf.ethz.ch Office: CAB E66 What will we do? Remark important concepts + exercises It is a cooperative session! Assignments: Not mandatory, not graded You get a feedback if you hand-in them (see Git tutorial) 2 Introduction
3
spcl.inf.ethz.ch @spcl_eth What is an Operating System? 3 Glue Referee Illusionist Which are the main roles of an OE? It’s an abstraction layer between the user and the hardware resources Referee: sharing, protection and communication Illusionist: create the illusion of a real resource (virtualization) Glue: Provide high-level abstraction, hiding details of hardware
4
spcl.inf.ethz.ch @spcl_eth General OS structure Kernel Privileged mode User mode Application System Library Application System Library Server process (daemon) Server process (daemon) System Library System calls CPU Device CPU 4
5
spcl.inf.ethz.ch @spcl_eth OS Kernel That part of the OS which runs in privileged mode Large part of Unix and Windows (except libraries) Small part of L4, Barrelfish, etc. (microkernels) Does not exist in some embedded systems Kernel is just a (special) computer program. Typically an event-driven server. Responds to multiple entry points: System calls Hardware interrupts Program traps May also include internal threads. 5
6
spcl.inf.ethz.ch @spcl_eth OS Kernel 6 Embedding applications in the kernel? Pros: PerformanceCons: Abstraction, Security, Bloated OS How kernel/user space distinction ensures security? User-space applications cannot issue all type of instructions Hardware devices can be accessed only in kernel mode Interrupts can be enabled/disabled only in kernel mode Btw, what happens if they could be managed in user mode? Which of the following operations should be privileged? Set a timer Turn off interrupts Create a process Issue a trap Read the clock
7
spcl.inf.ethz.ch @spcl_eth Recall: System Calls RPC to the kernel Kernel is a series of syscall event handlers Mechanism is hardware-dependent System calls Privileged mode User mode User process runs Process resumes Execute kernel code Execute syscall 7
8
spcl.inf.ethz.ch @spcl_eth System calls 8 What is the purpose of system calls? -Request services to the OS How would you create a new process? NAME fork - create a child process SYNOPSIS #include pid_t fork(void); DESCRIPTION fork() creates a new process by duplicating the calling process. The new process, referred to as the child, is an exact duplicate of the calling process, referred to as the parent … NAME fork - create a child process SYNOPSIS #include pid_t fork(void); DESCRIPTION fork() creates a new process by duplicating the calling process. The new process, referred to as the child, is an exact duplicate of the calling process, referred to as the parent … -Enable the OS abstraction -e.g., memory virtualization NAME execl, execlp, execle, execv, execvp, execvpe - execute a file SYNOPSIS #include int execv(const char *path, char *const argv[]); DESCRIPTION The exec() family of functions replaces the current process image with a new process image. The functions described in this manual page are front-ends for execve(2).
9
spcl.inf.ethz.ch @spcl_eth Process ingredients Virtual processor Address space Registers Instruction Pointer / Program Counter Program text (object code) Program data (static, heap, stack) OS “stuff”: Open files, sockets, CPU share, Security rights, etc. 9
10
spcl.inf.ethz.ch @spcl_eth Process address space Stack Text Data BSS 00000000 7FFFFFFF (addresses are examples: some machines used the top address bit to indicate kernel mode) Should look familiar … 10
11
spcl.inf.ethz.ch @spcl_eth Process lifecycle runnable (ready) running blocked (waiting) terminated created dispatch preemption I/O operation I/O completes runnable (ready) running runnable (ready) blocked (waiting) blocked (waiting) running runnable (ready) runnable (ready) 11
12
spcl.inf.ethz.ch @spcl_eth A process may create another process Parent-Child relation Process tree Unix: fork()/exec() The fork returns different values: At the parent: the Process ID (PID) of the children At the children: zero Both parent and child execute the same next line! The variables until the fork() are shared Usually the child executed an exec() to execute a different code Parent has to wait for the completion of its children wait/waitpid Otherwise you create zombies!!! 12 Processes Creation What is the return value of this function?
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.