0% found this document useful (0 votes)
17 views22 pages

Lec 01

The document outlines the agenda and key concepts related to operating systems, including their functionalities, importance, and basic principles of UNIX OS. It discusses the role of operating systems as resource managers, the significance of system calls, and the boot sequence. Additionally, it highlights the complexities of program execution and memory management, emphasizing the need for efficient virtualization and protection mechanisms.

Uploaded by

Sushi Keer
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views22 pages

Lec 01

The document outlines the agenda and key concepts related to operating systems, including their functionalities, importance, and basic principles of UNIX OS. It discusses the role of operating systems as resource managers, the significance of system calls, and the boot sequence. Additionally, it highlights the complexities of program execution and memory management, emphasizing the need for efficient virtualization and protection mechanisms.

Uploaded by

Sushi Keer
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

8/17/2022

Agenda
• Recap
• What is an operating system
• Why is it important
Operating Systems: What and Why • Summary of OS functionalities
• Basics of UNIX OS
• System calls
• Path of a system call
• User interfaces
• System boot sequence

Recap What is an operating system


• What do we know about computing systems • A piece of software application
– How to express algorithms in a programming • Resource manager of any computing system
language (ESC101) – Schedules resources like CPU, memory, hard disks,
– How to design basic digital logic blocks (ESC102) and other I/O devices
– Design of algorithms (ESO207) – Virtualizes the resources so that
– How to use the basic digital logic blocks to design • a programmer does not have to worry about the low-
simple computers (CS220) level details of a physical resource
• For example, using adders, shifters, and other basic • presents a virtual interface of the resource to the user
logic blocks, one can design an arithmetic logic unit
(ALU)

1
8/17/2022

Why is it important Why is it important


• Let’s assume that we have a minimal
hardware implementing some abstract
instruction set architecture
• Peripheral devices consist of memory, hard
disk, keyboard, and a display
• We have a simple problem to solve: add the
elements of a vector and print the result on
the display device
• Let’s assume that somebody has written the
program to solve it and prepared the binary
image of the executable

Why is it important Why is it important


• Q1: How do I store the binary image on hard • Q1: How do I store the binary image on hard
disk? Why is it important to store it on hard disk? disk? Why is it important to store it on hard disk?
– Learn to program the disk controller manually and
write a stream of bytes (how?)

2
8/17/2022

Why is it important Why is it important


• Q1: How do I store the binary image on hard • Q1: How do I store the binary image on hard
disk? Why is it important to store it on hard disk? disk? Why is it important to store it on hard disk?
– Learn to program the disk controller manually and – Learn to program the disk controller manually and
write a stream of bytes (how?) write a stream of bytes (how?)
• Q2: What if there isn’t enough contiguous space • Q2: What if there isn’t enough contiguous space
on disk? Is contiguous space necessary? on disk? Is contiguous space necessary?
– Learn to create this space (de-fragment)

Why is it important Why is it important


• Q1: How do I store the binary image on hard • Q1: How do I store the binary image on hard
disk? Why is it important to store it on hard disk? disk? Why is it important to store it on hard disk?
– Learn to program the disk controller manually and – Learn to program the disk controller manually and
write a stream of bytes (how?) write a stream of bytes (how?)
• Q2: What if there isn’t enough contiguous space • Q2: What if there isn’t enough contiguous space
on disk? Is contiguous space necessary? on disk? Is contiguous space necessary?
– Learn to create this space (de-fragment) – Learn to create this space (de-fragment)
• Q3: How do I load the binary image on memory? • Q3: How do I load the binary image on memory?
Why is it necessary? What if memory is small? Why is it necessary? What if memory is small?
– Learn to program the memory controller manually;
read from disk and write to memory

3
8/17/2022

Why is it important Why is it important


• Q4: How to start executing the executable?

Why is it important Why is it important


• Q4: How to start executing the executable? • Q4: How to start executing the executable?
– Learn to load the program counter with the – Learn to load the program counter with the
address of the first instruction of the executable address of the first instruction of the executable
– This is a sequence of instructions (how?) – This is a sequence of instructions (how?)
• Q5: How to read the vector size from
keyboard?

4
8/17/2022

Why is it important Why is it important


• Q4: How to start executing the executable?
– Learn to load the program counter with the
address of the first instruction of the executable
– This is a sequence of instructions (how?)
• Q5: How to read the vector size from
keyboard?
– The program must handle keyboard interrupts

Why is it important Why is it important


• Q6: How to allocate memory for the vector? • Q6: How to allocate memory for the vector?
– The program must create enough memory space
before the allocation

5
8/17/2022

Why is it important Why is it important


• Q6: How to allocate memory for the vector? • Q6: How to allocate memory for the vector?
– The program must create enough memory space – The program must create enough memory space
before the allocation before the allocation
• Q7: What if the vector size is larger than • Q7: What if the vector size is larger than
memory? memory?
– The program must check for this condition, divide
the vector in portions, implement a swapping
procedure, and operate only on portions that are
in memory

Why is it important Why is it important


• Q8: How is the final result displayed?

6
8/17/2022

Why is it important Why is it important


• Q8: How is the final result displayed? • Q8: How is the final result displayed?
– The program must send the final result to the – The program must send the final result to the
display device and command it to display the display device and command it to display the
communicated characters communicated characters
• Q9: How does the program terminate?

Why is it important Why is it important


• The example shows several interactions with
• Q8: How is the final result displayed? the hardware that the user program has to
– The program must send the final result to the take care of: write to disk, read from disk,
display device and command it to display the memory and disk management, read from
communicated characters keyboard, write to display, control start/stop
sequence on CPU
• Q9: How does the program terminate?
– Shows the importance virtualizing disk and
– A special instruction at the end can lead the CPU keyboard (as files?), memory, and CPU
to an “idle” state
• Very poor utilization of the CPU
– CPU is idle when swapping between disk and
memory or reading from keyboard or writing to
display

7
8/17/2022

Why is it important Why is it important


• Q10: Is it possible to run multiple programs in a
time-shared fashion? Also known as multi-
tasking or multi-programming

Why is it important Why is it important


• Q10: Is it possible to run multiple programs in a • Q10: Is it possible to run multiple programs in a
time-shared fashion? Also known as multi- time-shared fashion? Also known as multi-
tasking or multi-programming tasking or multi-programming
– A program before going on a long-latency event must – A program before going on a long-latency event must
save state in memory, restore saved state of another save state in memory, restore saved state of another
program, load it from disk, and start it from where it program, load it from disk, and start it from where it
left off left off
– Each program sees a virtual CPU

8
8/17/2022

Why is it important Why is it important


• Q10: Is it possible to run multiple programs in a • Q10: Is it possible to run multiple programs in a
time-shared fashion? Also known as multi- time-shared fashion? Also known as multi-
tasking or multi-programming tasking or multi-programming
– A program before going on a long-latency event must – A program before going on a long-latency event must
save state in memory, restore saved state of another save state in memory, restore saved state of another
program, load it from disk, and start it from where it program, load it from disk, and start it from where it
left off left off
– Each program sees a virtual CPU – Each program sees a virtual CPU
– How to manage memory of multiple programs? – How to manage memory of multiple programs?
• Each program sees a virtual view of the memory

Why is it important Why is it important


• Q10: Is it possible to run multiple programs in a • Q10: Is it possible to run multiple programs in a
time-shared fashion? Also known as multi- time-shared fashion? Also known as multi-
tasking or multi-programming tasking or multi-programming
– A program before going on a long-latency event must – A program before going on a long-latency event must
save state in memory, restore saved state of another save state in memory, restore saved state of another
program, load it from disk, and start it from where it program, load it from disk, and start it from where it
left off left off
– Each program sees a virtual CPU – Each program sees a virtual CPU
– How to manage memory of multiple programs? – How to manage memory of multiple programs?
• Each program sees a virtual view of the memory • Each program sees a virtual view of the memory
• Q11: What if there are many programs to select • Q11: What if there are many programs to select
from? from?
– Must invoke a “scheduling algorithm”

9
8/17/2022

Why is it important Why is it important


• The addition of vector elements now begins to • Q12: How to represent directories and
look really complicated subdirectories on a disk?
– The programmer needs to take care of too many – Call each independent entity on the disk a file.
things that have no relation to the actual problem Directories are also files. Need to implement all
• After working with this system for a while, you necessary functionalities of a “file system” e.g.,
creating a file, reading from a file, writing to file,
realize that the disk contents should be
etc.
organized in a better way
– Notice that all these have to be handled by the
– Related information should be grouped in a class end-user’s program which wishes to use the
(call it a directory) and each class may have capabilities of the file system
subclasses

Why is it important Why is it important


• One day you find that one program has • Every program needs to do a common set of
overwritten the data belonging to another things
program in memory due to a wrong address in – Read from keyboard
the former program – Write to display
• Q13: How to protect a program’s code and – Read from and write to disk
data from unintentional/intentional – Manage disk
bugs/attacks? – Manage memory
– Every program must incorporate an elaborate – Switch between programs or “jobs”
security solution – Select jobs for scheduling
– Every program’s memory must be isolated – Protect program code and data

10
8/17/2022

Why is it important Design goals of OS


• Back to the basic: pack commonly used • Efficient virtualization of physical resources
functionalities in a library • Efficient support for correct handling of
– Call the appropriate function from the library concurrent execution
whenever needed
• Still looks cumbersome: why should a • Efficient file system for persistent storage
programmer implement these calls? • Appropriate abstraction for each resource to
• Observation: every program is a marriage of make it easy to use
computation and these “system library calls” • Efficient means high-performance and low
• An operating system implements these system overhead in terms of space, time, energy
calls and takes over whenever such a service is • Protection, isolation, security
needed by a running job
– The C standard library is a wrapper around these
• Reliability and failure-freedom
system calls • Support for mobile devices

Summary of OS functionalities Summary of OS functionalities


• Two broad categories
– Functionalities to improve performance • Two modes of operations
• Job scheduling, context switch, memory management – User mode avoids catastrophic failures
– Functionalities to improve ease of use • Isolated virtual address space for each process in user
• File systems, I/O, security mode
• Isolated execution of each process
• Two modes of operations • No direct access to any hardware device
– User mode and kernel mode – CPU needs to support a mode bit as part of the
– A system call from a user program leads to a switch to machine status word or processor status word
kernel mode – Switching modes is expensive
– Kernel mode allows unrestricted access to hardware • Needs to save and restore user and kernel register states
including execution of privileged instructions

11
8/17/2022

Summary of OS functionalities Summary of OS functionalities


• System boots up in kernel mode
– Kernel of the OS is loaded by the bootstrap loader • OS does several book-keeping tasks
from a fixed location in the disk periodically
– Only when a user program is scheduled to run on
– Job scheduling is an important example
the CPU, does the mode bit switch to user mode
– Implemented by setting up a timer register which
• System calls invoke system call handlers
is decremented on every processor clock tick
– Locations of the handlers are found in an interrupt
vector table residing in the low memory – When the timer register expires, a hardware
interrupt is generated
– Hardware interrupts are handled in the same way
– System call arguments are passed in registers – The interrupt handler services the periodic tasks
and/or in memory (by passing a pointer in a one by one and sets up the timer register again
register); what are these arguments?

Summary of OS functionalities Summary of OS functionalities


• Four basic OS modules • Four basic OS modules
– Process management, memory management, storage – Storage management involves
management, protection • Implementing a virtual environment called file system
– Process management involves – Protection cross-cuts all the three modules
• Creation, deletion, scheduling of processes • Controls accesses to the resources managed by the OS
• Offering support for communication between processes • Usually the OS kernel is assumed to be trusted
• Synchronizing communicating processes • A stricter protection model requires hardware-
• Handling deadlocks supported security
– Memory management involves
• Handling memory allocation and de-allocation requests
from user and kernel mode processes

12
8/17/2022

Basics of the UNIX OS Basics of the UNIX OS


• Bit of history
– 1965: Bell Telephone Labs, General Electric Company,
and MIT join hands to build Multics (multiplexed
information and computing service)
• [Link]
– 1969: Early version of Multics runs on GE 645; Bell
Labs terminate participation
– 1970: Honeywell takes over GE along with Multics
– 1969-1971: Ken Thompson and Dennis Ritchie of Bell
Labs implement a minimal OS in Fortran on a PDP-7
machine, which was later migrated to a PDP-11
• Brian Kernighan names it UNIX, a pun on the name Multics
Reproduced from “The Design of the UNIX OS” by M J Bach
– 1973: UNIX gets rewritten in C (which grew out of B)

Basics of the UNIX OS Basics of the UNIX OS: File system


• Two major parts
– The OS kernel • Every I/O device is treated as a file
– Auxiliary system applications such as the shell – Keyboard is treated as a special file called the
command interpreter, the editors such as “vi”, etc. standard input
– Display device is standard output
• UNIX kernel talks to the system and user
applications through the system call layer • File system interacts with two types of I/O
– Two major sets of system calls: process control and devices
file system – Block device: transfers a block of data between the
– The process control layer implements inter-process device and the kernel e.g., hard disk
communication, scheduling, and memory – Character device: communicates through a stream of
management bytes e.g., keyboard, display, etc.

13
8/17/2022

Basics of the UNIX OS: File system Basics of the UNIX OS: File system
• Block devices • Files are maintained using a data structure called
– Accessed through a buffer cache to exploit spatial index node (inode for short) table
locality – Each file has one inode
– Seen by the kernel as random access storage – Each inode stores the disk layout of the file data and
devices even though physically they may not be other information such as file owner, access
• Character devices permissions, access times, etc.
– Directly talk to the kernel without any caching – On a file system call specifying a file name, the file
name is translated to the corresponding inode
• Even though the OS abstraction for a device is
• Maintains two more tables to do this: user file descriptor
a file, every device needs a device driver to table (UFDT) and kernel file table (FT)
implement the hardware protocols

Basics of the UNIX OS: File system Basics of the UNIX OS: File system
• UFDT and FT
– The UFDT maintains one entry for each open file of a
process
– The UFDT entry holds a pointer to the corresponding
FT entry; two UFDT entries may point to the same FT
entry (same file opened twice)
– The open or creat call returns the index of the UFDT
slot allocated to the file
• Referred to as a file descriptor
– Each FT entry stores the read/write byte offset into a
file, access permissions, a unique pointer to the file
Reproduced from “The Design of the UNIX OS” by M J Bach inode

14
8/17/2022

Basics of the UNIX OS: File system Basics of the UNIX OS: File system
• File systems are kept on the block devices
– Kernel remains oblivious to the physical block device • File system
addresses – Boot block resides in the first sector and contains the
– The translation from the logical file system layout to bootstrap loader
the physical addresses is done by the device driver – Superblock describes the state of the file system: how
– Kernel treats the file system as a sequence of logical large it is, how many files it can store, free list
blocks, each of size multiple of 512 bytes information, etc.
– A file system starts with a boot block followed by a – Inode list size is configured by the admin when
superblock, the inode list, and the data blocks building the kernel
– Inode table contains the indices into the inode list
– Root inode is used as the root of the directory system
– An allocated data block can belong to exactly one file
Reproduced from “The Design of the UNIX OS” by M J Bach

Basics of the UNIX OS: Process control Basics of the UNIX OS: Process control
• Kernel process table entry for each process and u
area to store process information manipulated by
kernel only
– Each process table entry points to a per process
region table and each per process region table entry
points to a global region table
– A region is a contiguous memory segment containing
process text, data, stack
– A global region table entry contains region attributes
such as text/data, private/shared, and the starting
Reproduced from “The Design of the UNIX OS” by M J Bach address of the region

15
8/17/2022

Basics of the UNIX OS: Process control Basics of the UNIX OS: Process control
• The u area contains information necessary to • The context of a process is its complete state
completely describe a process; kernel can including
directly access the u area of the currently – Text (code)
executing process only; the u area contains
– Values of global user variables and data structures
– A pointer to the kernel process table slot of the
currently executing process – Values of processor registers
– Parameters, return values, and error codes of the last – Contents of its kernel process table slot and u area
executed system call of the currently executing – Contents of its user mode stack and kernel mode
process stack
– File descriptors of all open files of the currently
executing process
– Current directory and current root of the file system
– Process and file size limits

Basics of the UNIX OS: Process control Basics of the UNIX OS: Process control
• A process undergoes several state transitions
from creation to termination • Three important system calls for process
– The kernel process table entry maintains the process management
state, user id of the owner, and an event descriptor if – execv, fork, wait
the process is in sleep state – An execv call from a user program executes a new
– A process undergoes a context switch on I/O or program, starting address of which is passed to the
hardware interrupt or timer interrupt call; does not create a new process
• Not all system calls cause a context switch
• Overlays new text, data, stack regions on top of the old
• All system calls cause a mode switch regions, sets up the region table pointers correctly
• Context switch code or system call code executes in the
context of the currently scheduled process – A fork call creates a new process (called the child
• A mode switch changes the stack frame top pointer to user process)
mode or kernel mode stack top depending on the direction • Kernel duplicates the address space for the child from the
of the switch parent by copying or sharing depending on the situation

16
8/17/2022

Basics of the UNIX OS: Process control Basics of the UNIX OS: Process control
• The processes form a tree
• A process is always created by another process
– The root of this tree in UNIX is init
– Created process is the child of the creating process
– The system boot process is killed after init is created
• The system boots up as a process
• The pstree command shows the process tree in
– init process in UNIX UNIX (pstree –p shows the pid also)
– This is the root of all processes
• The pgrep processname command shows the pid
– Every process gets a unique integer ID known as the
of a process
process ID or pid. The root process has pid zero.
• In UNIX, the system boot process has pid zero and init has – pgrep init returns 1
pid one. • To find the parent pid of a process with pid x
– Check the fourth entry in file /proc/x/stat on UNIX
– In a C program, you can use getppid()

Basics of the UNIX OS: Process control Basics of the UNIX OS: Process control
• A process can be created by calling fork()
– Child pid is returned to parent, zero is returned to • The wait() system call makes a process wait for
child. A negative return value indicates error in UNIX. any one of its children to complete
• When the fork() call returns • It is a good practice to wait for all the children
– The child process has been created that a process has created
– Its text and global data are loaded in memory – Can be programmed using a loop which runs number
– The process will start executing when it is scheduled of times equal to the number of children
– Since the child process gets an exact copy of the
– Each loop iteration makes one call to wait()
address space and registers of the parent, it starts
executing at the instruction that returns from fork() – The wait() call takes one argument which is a pointer
• This is the value of the program counter in the parent to the exit code of a completing child process
• The only difference between the parent and the child is in • Can be passed NULL if we do not need the exit code of a
the return value of the fork() call child process

17
8/17/2022

Basics of the UNIX OS: Process control Basics of the UNIX OS: Process control
• The waitpid() system call makes a process wait • The pipe() system call creates a communication
for the child with a specific pid channel with a write end and a read end
– Takes three arguments: pid, exit code pointer, an – The ends of a pipe are implemented using a pair of
option file descriptors corresponding to a “common” file
– First argument can be -1 if any child is waited for – A process can write to one end and read what it has
– The last argument is usually 0 written from the other end
– waitpid(-1, &status, 0) is equivalent to wait(&status) • Not very interesting for a process to do so
• Gets interesting when one process writes to one end of the
– A useful value for the last argument of waitpid is pipe and another process reads from the other end
WNOHANG
– The pipe() call takes an array of two file descriptors as
• Allows the parent to return immediately irrespective of
whether the child waited for has completed or not
argument
• On return, the array is filled up appropriately by OS

Basics of the UNIX OS System calls


• External hardware interrupts • General mechanism of virtualizing a physical
– OS may delay handling these if currently in the kernel resource
mode depending on the criticality of the code being – Map virtual entities on to the physical resource in a
executed time-shared manner
– Every interrupt has a priority level • Swap out a virtual entity to make room for another virtual
– To mask an interrupt, the processor execution priority entity
level is raised above the priority level of the interrupt – Needed only if the physical resource is exhausted

• For example, before manipulating the inode list, the • Swap in the new virtual entity to occupy (portion of) the
processor priority level is raised above the disk interrupt physical resource
priority level – Example: physical resource CPU is time-shared
– Typical interrupt priority (low to high): software between virtual entities named “processes”
interrupts (system calls), character devices, network, – Example: physical resource memory is time-shared
disk, timer, machine error between virtual entities named “address spaces”

18
8/17/2022

System calls System calls


• General goals of CPU virtualization • OS defines a set of restricted operations
– Performance: a process should be able to run at – Usually involves accessing some other resource such
native CPU speed with minimum OS interference as an I/O device, or allocating some resource such as
– OS control: periodically/occasionally the OS should be memory, etc.
able to get control over what the CPU does – OS would like to check whether such an operation is
– The two goals have somewhat contradictory legitimate before letting the currently running
demands process do it
• A middle ground is possible meaning that some OS • A process normally runs in user mode
interference must be tolerated
– Can do everything except any of the restricted
• System calls play an important role in letting the operations
OS control what other resources the CPU can • A process must switch to kernel mode to do a
access restricted operation

System calls System calls


• How does a process switch between user and • Steps involved in handling a trap
kernel modes? – Must be transparent to the currently running process
– By executing a system call instruction (known as ecall – Switch mode to kernel
in RISC-V ISA) a user mode to kernel mode switch can – Trap handler saves registers and other necessary
be achieved states on kernel stack so that the running process can
– Sometimes it is wrongly referred to as a trap be resumed correctly after returning from trap
instruction – Handle system call (invokes a system call handler
• Actually, there is no trap instruction; instead, trap is a routine)
mechanism for the CPU to transfer control to the OS – Restore registers and other states from kernel stack
• Trapping the process in a small cage to do the required – Return from trap (switches mode and stack to user)
restricted operation only and nothing else
– A special return instruction (sret in RISC-V) switches • A newly created process also switches to user
the mode from kernel to user mode through the return from trap instruction

19
8/17/2022

System calls System calls


• How to locate the trap handler entry point? • System calls have a lot of resemblance with
– The system call instruction jumps to a location stored function calls
in a privileged register (written using privileged inst.) – The arguments of a system call are usually passed in
– In RISC-V, this is the stvec register the same registers used to pass function arguments
• Supervisor trap vector base address register – The return value of a system call uses the same
– In other architectures, this may come in the form of a register used for returning value from functions
table or a vector – There is a reason behind this resemblance
• Depending on the cause of the trap, a particular entry in • System calls are usually wrapped around by library
the vector is used as the jump address functions e.g., system call to write to a file would be part of
– The stvec register or the trap table is set up by the OS the fprintf function’s code
kernel as part of the boot code • Keeping the same calling convention for syscalls and
• Recall that a machine boots up in kernel mode and functions makes it easy to pass arguments and return
therefore, the boot process can do privileged operations results

System calls Path of a system call


• How to distinguish between different system • Assume the RISC-V UNIX like platform
calls? • RISC-V system call convention (integer args)
– Memory allocation, file read, file write, sleep, exit, – System call arguments are passed in registers 10, 11, …,
fork, execv, wait, etc. 16 (aka a0 to a6; same as function call args)
– To distinguish among these, a system call instruction – System call number is passed in register 17 (aka a7)
has a special argument called the system call number – No system call has more than six args; so a6 is not used
– Different system calls have different numbers – System call return value is in registers a0 and a1
– The basic xv6 kernel has 21 system calls exposed to • Only a0 will be used in xv6
user programs – System call instruction in RISC-V is ecall
– Each system call is exposed to user programs through • Consider the read system call for reading from a file
one or a group of wrapper functions – C library calls read, fscanf, scanf, etc. all lead to this
• For example, fopen() is a wrapper around the open syscall system call

20
8/17/2022

Path of a system call Path of a system call


• The read system call handler
• The read system call – If the file descriptor is bigger than two, various
– Three arguments: file descriptor (in register a0), permission checks are done in the GFT and the UFDT
destination memory buffer address (in register a1), – The inode is accessed and the data bytes are read
number of bytes to read (in register a2) from either the buffer cache or the disk if the file
descriptor is bigger than 2; otherwise the bytes are
– These registers should be set up before the syscall read from the character device
instruction executes
– The data bytes are written to the memory buffer by
– The ecall instruction stops instruction fetching, waits setting up a DMA depending on the device driver
for all pending instructions to complete, does a mode interface
switch, invokes the appropriate system call handler – After initiating the DMA, a context switch can take
after examining register a7 place
– The system call returns the number of bytes read

Path of another system call Path of yet another system call


• Consider the open system call • Consider the exit system call
– Used to open a file – Every program on termination invokes this system call
– Takes two arguments: file name (pointer in register • In C programs after the main function returns, the exit
a0), access flags and permission mode flags if the file system call gets invoked
is to be created (in register a1) – Takes one argument: the exit code (in register a0)
– The system call handler allocates a free file descriptor – The system call handler deletes the calling process
by looking up the UFDT and GFT, sets the permission – An example of a system call belonging to the process
bits in the allocated entry according to the flags, management subsystem
retrieves the inode and puts it in the inode cache
– The normal return value of the system call is the
allocated file descriptor id

21
8/17/2022

User interfaces A skeleton shell


• Two types: command line interface and graphical while (1) {
user interface (GUI) // read command into character array buf[][]
– Command line interface is provided by a shell if (buf[0] is “exit”) break;
program or a command line interpreter
– The shell can be implemented in two ways else if (program with name equal to buf[0] exists)
• A command line parser interprets the user’s command and { if (fork() == 0) execv (buf[0], buf);
executes it (MS-DOS style) else {
• A command line interface program only checks if the
command exists, forks a child, and passes the command if (last character in buf is not `&’) wait(NULL);
line to the child for execution (mostly used today) }
• The fork model allows background and concurrent
execution of commands } else printf(“%s: command not found.\n”,buf[0]);
– A GUI usually involves a large number of system calls }

System boot sequence


• Boot sequence involves the following steps
– Run diagnostic codes from a ROM or EEPROM
– Load the bootstrap loader from the boot block
– The bootstrap loader loads the necessary parts of the
kernel
• The bootstrap loader can be changed easily by
modifying the boot block only
• A boot disk or a system disk contains the
bootstrap loader

22

You might also like