Operating System –Class III
UNIT I
UNIT I OPERATING SYSTEM OVERVIEW 7
Computer System Overview-Basic Elements, Instruction Execution,
Interrupts, Memory Hierarchy, Cache Memory, Direct Memory Access,
Multiprocessor and Multicore Organization.
Operating system overview-objectives and functions, Evolution of
Operating System. - Computer System Organization Operating System
Structure and Operations- System Calls, System Programs, OS
Generation and System Boot.
System Call
• Way for a user program to interface with the operating system
• A system call is a method for a computer program to request a service
from the kernel of the operating system on which it is running.
• Mostly accessed by programs via a high- level Application
Programming Interface (API) rather than direct system call
• Kernel is the essential center of a computer operating system (OS).
• It is the core that provides basic services for all other parts of the OS.
• It is the main layer between the OS and hardware.
• Helps with process and memory management, file systems, device control and
networking.
System Calls Vs User function
How a system call varies from a user function.
• A system call function may create and use kernel processes to execute
the asynchronous processing.
• A system call has greater authority than a standard subroutine. A
system call with kernel-mode privilege executes in the kernel
protection domain.
• The code and data for system calls are stored in global kernel
memory.
A View of Operating System Services
Example of System Calls
• System call sequence to copy the contents of one file to
another file
Example of Standard API
System Call Implementation
• Typically, a number is associated with each system call
– System-call interface maintains a table indexed according to
these numbers
• The system call interface invokes the intended system call in OS
kernel and returns status of the system call and any return
values
• The caller need not know a thing about how the system call is
implemented
– Just needs to obey the API and understand what the OS will
do as a result call
– Most details of OS interface hidden from programmer by API
• Managed by run-time support library (set of functions
built into libraries included with compiler)
System Call -- OS Relationship
The handling of a user application invoking the open() system call
System Call Parameter Passing
• Three general methods used to pass parameters to the OS
– Simplest: pass the parameters in registers
• In some cases, may be more parameters than registers
– Parameters stored in a block, or table, in memory, and address of block passed as a
parameter in a register
• This approach taken by Linux and Solaris
– Parameters placed, or pushed, onto the stack by the program and popped off
the stack by the operating system
– Block and stack methods do not limit the number or length of parameters being
passed
x points to a block of parameters. x is loaded into a register
Parameter Passing via Table
Types of System Calls
• System calls can be grouped roughly into six major
categories:
– Process control,
– File manipulation,
– Device manipulation,
– Information maintenance,
– Communications,
– Protection.
System Calls – Process Control
• create process, terminate process
• end, abort
• load, execute
• get process attributes, set process attributes
• wait for time
• wait event, signal event
• allocate and free memory
• Dump memory if error
• Debugger for determining bugs, single step execution
• Locks for managing access to shared data between
processes
System Calls – File
Management
• Create file
• Delete file
• Open and Close file
• Read, Write, Reposition
• Get and Set file attributes
System Calls – Device Management
• request device, release device
• read, write, reposition
• get device attributes, set device attributes
• logically attach or detach devices
System Calls -- Information
Maintenance
• get time or date,
• set time or date
• get system data,
• set system data
• get and set process, file, or device attributes
System Calls -- Information Maintenance
• get time or date,
• set time or date
• get system data,
• set system data
• get and set process, file, or device attributes
System Calls – Communications
• create, delete communication connection
• if message passing model:
– send, receive message
• To host name or process name
• From client to server
• If shared-memory model:
– create and gain access to memory regions
• transfer status information
• attach and detach remote devices
System Calls -- Protection
• Control access to resources
• Get and set permissions
• Allow and deny user access
Examples of Windows and Unix System Calls
Example -- Standard C Library
C program invoking printf() library call, which calls write() system call
Program
• Program using fork, getpid, getppid system calls
• Programs using exec System calls
• Program using opendir, readdir, closedir system calls
• Program using stat system calls
• Programs using open and close system call
fork( )
• Used to create new processes.
• The new process consists of a copy of the address space of the
original process.
• The value of process id for the child process is zero.
• The value of process id for the parent is an integer value greater than
zero.
getpid( ) & getppid()
• getpid()
• Each process is identified by its id value.
• This function is used to get the id value of a particular process
• getppid()
• Used to get particular process parent‘s id value.
• perror()
• Indicate the process error
Sample Program
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/wait.h>
int main() {
int forkStatus;
int pid;
int ppid;
forkStatus = fork();
/* Child... */
if(forkStatus == 0) {
printf("\n Child process:");
pid = getpid();
ppid = getppid();
printf("\nChild's Process id: %d",pid);
printf("\nParent's Process id: %d",ppid);
/* Parent... */
} else if (forkStatus != -1) {
printf("\n Parent process:");
pid=getpid();
printf("\nProcess id: %d",pid);
} else {
perror("Error while calling the fork function");
}
,/; ‗‘
.k
return 0;
}
Output
rit@rit-OptiPlex-3010:~/Documents$ gcc forktest.c
rit@rit-OptiPlex-3010:~/Documents$ ./a.out
Parent process:
Process id: 4177
Child process:
Child's Process id: 4178
Parent's Process id: 4177
wait() System Call
wait( )
• The parent waits for the child process to complete using the wait
system call.
• The wait system call returns the process identifier of a terminated
child, so that the parent can tell which of its children has terminated.
Syntax : wait( NULL)
exit( )
• A process terminates when it finishes executing its final statement
and asks the operating system to delete it by using the exit system
call.
• At that point, the process may return data (output) to its parent
process (via the wait system call).
exec system calls
• exec type system calls allow a process to run any program files,
which include a binary executable or a shell script .
• exec is used when the user wants to launch a new file or program in
the same process.