System_Calls - Thislecture CS241SystemsProgramming...

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

View Full Document Right Arrow Icon
Copyright ©: University of Il inois CS 241 Staff 1 CS241 Systems Programming System Calls and I/O This lecture Goals ± do programming Things covered in this lecture ± Basic file system calls ± I/O calls ± Signals Note: we will come back later to discuss the above  things at the concept level Copyright ©: University of Il inois CS 241 Staff 2 System Calls versus Function  Calls? Copyright ©: University of Il inois CS 241 Staff 3 Process Caller and callee are in the same Process - Same user - Same “domain of trust” Function Call System Calls versus Function  Calls Copyright ©: University of Il inois CS 241 Staff 4 fnCall() System Calls versus Function  Calls Copyright ©: University of Il inois CS 241 Staff 5 fnCall() Process Caller and callee are in the same Process - Same user - Same “domain of trust” Function Call sysCall() Process System Call OS - OS is trusted; user is not. - OS has super-privileges; user does not - Must take measures to prevent abuse System Calls System Calls ± A request to the operating system to perform some activity System calls are expensive ± The system needs to perform many things before  executing a system call The computer (hardware) saves its state  The OS code takes control of the CPU, privileges are  updated.  The OS examines the call parameters  The OS performs the requested function The OS saves its state (and call results)  The OS returns control of the CPU to the caller  Copyright ©: University of Il inois CS 241 Staff 6
Background image of page 1

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

View Full DocumentRight Arrow Icon
Steps for Making a System  Call (Example: read call) Copyright ©: University of Il inois CS 241 Staff 7 3: Push  parameter (in  reverse order) 5: Library call 6: Switch to kernel  mode 7: Find system call  handler 8: Run handler 9: Return to user  mode 10: Return to user  program 11: Clean up Examples of System Calls Examples ± getuid() //get the user ID ± fork() //create a child process ± exec() //executing a program Don’t mix system calls with standard library calls ± Differences? ± Is  printf() a system call? ± Is  rand() a system call? Copyright ©: University of Il inois CS 241 Staff 8 man syscalls Major System Calls Process Management pid = fork( ) Create a child process identical to the parent  Wait for a child to terminate s = execve(name, argv, environp) Replace a process’ core image exit(status) Terminate process execution and return status  Copyright ©: University of Il inois CS 241 Staff 9 File Management fd = open(file, how, . ..) Open a file for reading, writing or both  s = close(fd) Close an open file  n = read(fd, buffer, nbytes) Read data from a file into a buffer  n = write(fd, buffer, nbytes) Write data from a buffer into a file 
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 07/10/2011 for the course CS 241 taught by Professor Campbell during the Spring '08 term at University of Illinois, Urbana Champaign.

Page1 / 6

System_Calls - Thislecture CS241SystemsProgramming...

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