DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING
CSS308 – OPERATING SYSTEMS
IIIYEAR / V SEMESTER
Prepared by
Dr.Thanuja R
Assistant Professor/ CSE
UNIT-I
OPERATING SYSTEMS OVERVIEW
CSS308-OPERATING SYSTEMS / Dr.Thanuja R/ AP/ CSE
Introduction: What Operating systems do - Structure -
Operations - Process management -Operating system Structure:
Services - User Interfaces - Systems calls and types – Systems
programs - Design and implementation - Operating System
Structure - System boot
SystemCalls
 Programminginterface to the servicesprovided by the O
S
 Typicallywritten in ahigh-levellanguage(Cor C++)
 Mostly accessed by programs via a high-level Application Programming
Interface(API)rather than direct systemcalluse
 Three most common APIs are Win32 API for Windows, POSIXAPI for
POSIX-basedsystems (including virtually all versions of UNIX, Linux, and
MacO
SX),andJavaAPIfor the Javavirtual machine (JVM)
CSS308-OPERATING SYSTEMS / Dr.Thanuja R/ AP/ CSE
Exampleof SystemCalls
 Systemcall sequenceto copythe contents of one file to another file
4
SystemCallImplementation
Typically,anumber associatedwith eachsystemcall
System-callinterfacemaintains atable indexedaccordingto these
numbers
The system call interface invokes the intended system call in OS
kernel and returns status of the systemcall and any return values
The caller need know nothing about how the system call is
implemented
Justneedsto obeyAPIandunderstand what OSwill do asaresult call
Most details of OSinterface hidden from programmer byAPI
Managedbyrun-time supportlibrary (set of functionsbuilt into libraries
included with compiler)
Why we use APIs rather than system call?
CSS308-OPERATING SYSTEMS / Dr.Thanuja R/ AP/ CSE
API–SystemCall–OSRelationship
CSS308-OPERATING SYSTEMS / Dr.Thanuja R/ AP/ CSE
SystemCallParameter Passing
Often, more information isrequired than simplyidentity of
desired systemcall
Exacttype andamount of information vary accordingtoOSand call
Threegeneral methods usedto passparameters to theOS
Simplest: passthe parameters inregisters
 In somecases,maybe more parameters thanregisters
Parametersstored in ablock, or table, inmemory, and addressof block
passedasaparameter in aregister
Thisapproach taken by LinuxandSolaris
Parametersplaced, or pushed,onto the stackby theprogram and
poppedoff the stackby the operatingsystem
Blockandstackmethods do not limit the number or length of
parameters beingpassed
CSS308-OPERATING SYSTEMS / Dr.Thanuja R/ AP/ CSE
Parameter Passingvia Table
CSS308-OPERATING SYSTEMS / Dr.Thanuja R/ AP/ CSE
Typesof SystemCalls
Typesof SystemCalls
Processcontrol
create process,terminateprocess
end, abort
load, execute
get processattributes, set processattributes
wait fortime
wait event, signalevent
allocate and free memory
Dump memory if error
Debuggerfor determining bugs,singlestep execution
Locksfor managingaccessto shareddata betweenprocesses
CSS308-OPERATING SYSTEMS / Dr.Thanuja R/ AP/ CSE
Typesof SystemCalls
 Filemanagement
 create file, deletefile
 open, closefile
 read, write, reposition
 get and set fileattributes
 Devicemanagement
 request device, releasedevice
 read, write, reposition
 Get& set deviceattributes
 logically attach or detachdevices
 Protection
 Control accessto resources
 Getand setpermissions
 Allow and denyuseraccess
 Information maintenance
 gettime or date,set time or date
 get systemdata, set systemdata
 get and set process,file, ordevice
attributes
 Communications
 create, delete communication
connection
 send,receive messagesif message
passingmodelto hostnameor
processname
Fromclientto server
 Shared-memorymodelcreate and
gainaccessto memoryregions
 transfer statusinformation
 attach and detach remotedevices
Pipe() system call Communications
PIPE() …
•int pipe(int fds[2]);
Parameters :
• fd[0] will be the fd(file descriptor) for the read
end of pipe.
•fd[1] will be the fd for the write end of pipe.
Returns : 0 on Success. -1 on error.
Ex:Windows and Unix SystemCalls
StandardCLibraryExample
 C program invoking
printf() library call,
which calls write()
system call
CSS308-OPERATING SYSTEMS / Dr.Thanuja R/ AP/ CSE
Example:MS-DOS
 Single-tasking
 Shellinvoked whensystem
booted
 Simplemethod torun
program
 Noprocesscreated
 Singlememory space
 Loadsprogram into memory,
overwriting all but thekernel
 Programexit ->shellreloaded
At system startup running a program
CSS308-OPERATING SYSTEMS / Dr.Thanuja R/ AP/ CSE
Example:FreeBSD
 Unix variant
 Multitasking
 Userlogin ->invokeuser’schoiceofshell
 Shellexecutesfork() systemcall tocreate
process
Executesexec()to load programinto
process
Shellwaits for processto terminateor
continues with usercommands
 Processexits with:
 code=0 –no error
 code>0 –error code
CSS308-OPERATING SYSTEMS / Dr.Thanuja R/ AP/ CSE
CSS308-OPERATING SYSTEMS / Dr.Thanuja R/ AP/ CSE

1.7 system calls

  • 1.
    DEPARTMENT OF COMPUTERSCIENCE & ENGINEERING CSS308 – OPERATING SYSTEMS IIIYEAR / V SEMESTER Prepared by Dr.Thanuja R Assistant Professor/ CSE
  • 2.
    UNIT-I OPERATING SYSTEMS OVERVIEW CSS308-OPERATINGSYSTEMS / Dr.Thanuja R/ AP/ CSE Introduction: What Operating systems do - Structure - Operations - Process management -Operating system Structure: Services - User Interfaces - Systems calls and types – Systems programs - Design and implementation - Operating System Structure - System boot
  • 3.
    SystemCalls  Programminginterface tothe servicesprovided by the O S  Typicallywritten in ahigh-levellanguage(Cor C++)  Mostly accessed by programs via a high-level Application Programming Interface(API)rather than direct systemcalluse  Three most common APIs are Win32 API for Windows, POSIXAPI for POSIX-basedsystems (including virtually all versions of UNIX, Linux, and MacO SX),andJavaAPIfor the Javavirtual machine (JVM) CSS308-OPERATING SYSTEMS / Dr.Thanuja R/ AP/ CSE
  • 4.
    Exampleof SystemCalls  Systemcallsequenceto copythe contents of one file to another file 4
  • 5.
    SystemCallImplementation Typically,anumber associatedwith eachsystemcall System-callinterfacemaintainsatable indexedaccordingto these numbers The system call interface invokes the intended system call in OS kernel and returns status of the systemcall and any return values The caller need know nothing about how the system call is implemented Justneedsto obeyAPIandunderstand what OSwill do asaresult call Most details of OSinterface hidden from programmer byAPI Managedbyrun-time supportlibrary (set of functionsbuilt into libraries included with compiler) Why we use APIs rather than system call? CSS308-OPERATING SYSTEMS / Dr.Thanuja R/ AP/ CSE
  • 6.
  • 7.
    SystemCallParameter Passing Often, moreinformation isrequired than simplyidentity of desired systemcall Exacttype andamount of information vary accordingtoOSand call Threegeneral methods usedto passparameters to theOS Simplest: passthe parameters inregisters  In somecases,maybe more parameters thanregisters Parametersstored in ablock, or table, inmemory, and addressof block passedasaparameter in aregister Thisapproach taken by LinuxandSolaris Parametersplaced, or pushed,onto the stackby theprogram and poppedoff the stackby the operatingsystem Blockandstackmethods do not limit the number or length of parameters beingpassed CSS308-OPERATING SYSTEMS / Dr.Thanuja R/ AP/ CSE
  • 8.
    Parameter Passingvia Table CSS308-OPERATINGSYSTEMS / Dr.Thanuja R/ AP/ CSE
  • 9.
  • 10.
    Typesof SystemCalls Processcontrol create process,terminateprocess end,abort load, execute get processattributes, set processattributes wait fortime wait event, signalevent allocate and free memory Dump memory if error Debuggerfor determining bugs,singlestep execution Locksfor managingaccessto shareddata betweenprocesses CSS308-OPERATING SYSTEMS / Dr.Thanuja R/ AP/ CSE
  • 11.
    Typesof SystemCalls  Filemanagement create file, deletefile  open, closefile  read, write, reposition  get and set fileattributes  Devicemanagement  request device, releasedevice  read, write, reposition  Get& set deviceattributes  logically attach or detachdevices  Protection  Control accessto resources  Getand setpermissions  Allow and denyuseraccess  Information maintenance  gettime or date,set time or date  get systemdata, set systemdata  get and set process,file, ordevice attributes  Communications  create, delete communication connection  send,receive messagesif message passingmodelto hostnameor processname Fromclientto server  Shared-memorymodelcreate and gainaccessto memoryregions  transfer statusinformation  attach and detach remotedevices
  • 12.
    Pipe() system callCommunications
  • 13.
    PIPE() … •int pipe(intfds[2]); Parameters : • fd[0] will be the fd(file descriptor) for the read end of pipe. •fd[1] will be the fd for the write end of pipe. Returns : 0 on Success. -1 on error.
  • 14.
    Ex:Windows and UnixSystemCalls StandardCLibraryExample  C program invoking printf() library call, which calls write() system call CSS308-OPERATING SYSTEMS / Dr.Thanuja R/ AP/ CSE
  • 15.
    Example:MS-DOS  Single-tasking  Shellinvokedwhensystem booted  Simplemethod torun program  Noprocesscreated  Singlememory space  Loadsprogram into memory, overwriting all but thekernel  Programexit ->shellreloaded At system startup running a program CSS308-OPERATING SYSTEMS / Dr.Thanuja R/ AP/ CSE
  • 16.
    Example:FreeBSD  Unix variant Multitasking  Userlogin ->invokeuser’schoiceofshell  Shellexecutesfork() systemcall tocreate process Executesexec()to load programinto process Shellwaits for processto terminateor continues with usercommands  Processexits with:  code=0 –no error  code>0 –error code CSS308-OPERATING SYSTEMS / Dr.Thanuja R/ AP/ CSE
  • 17.
    CSS308-OPERATING SYSTEMS /Dr.Thanuja R/ AP/ CSE