05-syscalls

05-syscalls - CS241 Systems Programming System Calls and...

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

View Full Document Right Arrow Icon
Copyright ©: University of Illinois CS 241 Staff 1 CS241 Systems Programming System Calls and I/O
Background image of page 1

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

View Full DocumentRight Arrow Icon
This lecture Goals Get you familiar with necessary basic system & I/O calls to 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 Illinois CS 241 Staff 2
Background image of page 2
System Calls versus Function Calls? Copyright ©: University of Illinois CS 241 Staff 3
Background image of page 3

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

View Full DocumentRight Arrow Icon
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 Illinois CS 241 Staff 4 fnCall()
Background image of page 4
System Calls versus Function Calls Copyright ©: University of Illinois 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
Background image of page 5

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

View Full DocumentRight Arrow Icon
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 Illinois CS 241 Staff 6
Background image of page 6
Steps for Making a System Call (Example: read call) Copyright ©: University of Illinois CS 241 Staff 7 1 – 3: Push parameter (in reverse order) 4 – 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
Background image of page 7

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

View Full DocumentRight Arrow Icon
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 Illinois CS 241 Staff 8 man syscalls
Background image of page 8
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 Illinois 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 position = lseek(fd, offset, whence) Move the file pointer Get a file’s status information
Background image of page 9

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

View Full DocumentRight Arrow Icon
Directory and File System Management s = mkdir(name, mode) Create a new directory
Background image of page 10
Image of page 11
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 34

05-syscalls - CS241 Systems Programming System Calls and...

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

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