Chapter 3 Basics of UNIX System Calls
Chapter 3 Basics of UNIX System Calls
1
Introduction
2
Kernel
4
OS Services
5
System Calls
• Definitions
• A request to the operating system to perform some
activity
• Well-defined entry point into kernel to request a service
• Collection of routines which are programmer’s functional
interface to the UNIX kernel.
• System calls are just like library routines, except that they
perform a subroutine call directly into the heart of UNIX.
• User programs make use of the kernel via the system call
interface
6
Executing a System Call
8
System calls vs Library calls
9
System and Library Calls
Files
open close read write lseek unlink chown dup2 special Directory
13
Process Management System call hierarchy
Process management
14
Error-Handling hierarchy
Error handling
perror
15
System calls summary
• Error Handling:
• perror()
• Regular file management:
• how to create, open, close, read, and write
regular files.
• Process management:
• how to duplicate, differentiate, suspend, and
terminate processes and briefly discusses
multithreaded processes.
16
System calls summary
interprocess communication.
17
Application Programming Interface
18
UNIX API Invocation Example
19
Win32 API Example
23
Error Handling
24
System calls summary
25
Error Handling: errno
$ showErrno.c
#include <stdio.h>
#include <sys/file.h>
#include <errno.h>
main(){
int fd;
/* Open a nonexistent file to cause an error */
fd = open(“nonexist.txt”, O_RDONLY);
if ( fd==-1 ) /* fd == -1 , an error occurred */
{
printf( “errno = %d \n”, errno );
perror(“main”);
}
fd=open( “/”, O_WRONLY ); /* Force a different error */
if ( fd== -1 )
{ printf(“errno=%d\n”, errno);
perror(“main”); } 29
Error Handling: perror()
31