Lecture%2021%20-%20Systems%20Programming

Lecture 21 S - Lecture 21 Systems Programming in C A C program can invoke UNIX system calls directly A system call can be defined as a request to

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
Copyright @ 2009 Ananda Gunawardena Lecture 21 Systems Programming in C A C program can invoke UNIX system calls directly. A system call can be defined as a request to the operating system to do something on behalf of the program. During the execution of a system call , the mode is change from user mode to kernel mode (or system mode) to allow the execution of the system call. The kernel, the core of the operating system program in fact has control over everything. All OS software is trusted and executed without any further verification. All other software needs to request kernel mode using specific system calls to create new processes and manage I/O. A process is a currently executing instance of a program. All programs by default execute in the user mode. A high level programmer does not have to worry about the mode change from user-mode to kernel-mode as it is handled by a predefined library of system calls. Unlike processes in user mode, which can be replaced by another process at any time, a process in kernel mode cannot be arbitrarily replaced by another process. A process in kernel mode can only be suspended by an interrupt or exception. A C system call software instruction generates an OS interrupt commonly called the operating system trap . The system call interface handles these interruptions in a special way. The C library function passes a unique number corresponding to the system call to the kernel, so kernel can determine the specific system call user is invoking. After executing the kernel command the operating system trap is released and the system returns to user mode. Unix system calls are primarily used to manage the file system or control processes or to provide communication between multiple processes. A subset of the system calls include creat( ), open( ), close( ) -- managing I/O channels read( ), write( ) – handling input and output operations lseek( ) – for random access of files link( ), unlink( ) – aliasing and removing files stat( ) – getting file status access( ), chmod( ), chown( ) – for access control exec( ), fork( ), wait( ), exit( ) --- for process control getuid( ) – for process ownership getpid( ) -- for process ID signal( ) , kill( ), alarm( ) – for process control chdir( ) – for changing working directory mmap(), shmget(), mprotect(), mlock() – manipulate low level memory attributes time(), gettimer(), settimer(),settimeofday(), alarm() – time management functions pipe( ) – for creating inter-process communication
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Copyright @ 2009 Ananda Gunawardena System calls interface often change and therefore it is advisable to place system calls in subroutines so subroutines can be adjusted in the event of a system call interface change. When a system call causes an error, it returns -1 and store the error number in a variable
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 11/27/2009 for the course CS 123 taught by Professor Bajkzek during the Fall '08 term at Carnegie Mellon.

Page1 / 10

Lecture 21 S - Lecture 21 Systems Programming in C A C program can invoke UNIX system calls directly A system call can be defined as a request to

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online