





































Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
An overview of various linux system calls related to process control, file manipulation, and i/o operations. Topics include fork, execl, wait, signal, open, read, write, creat, unlink, chmod, fcntl, mmap, and munmap. Understand how these system calls are used to create, manage, and manipulate files and processes.
Typology: Study notes
1 / 45
This page cannot be seen from the preview
Don't miss anything!






































15-213, F’ 02
15-213, F’ 02
open
open
get a file descriptor for named file
get a file descriptor for named file
close
close
free a file descriptor
free a file descriptor
read
read
read
read data from a file descriptor
data from a file descriptor
write
write
write
write data to a file descriptor
data to a file descriptor
stat
stat
get file meta data
get file meta data
dup
dup
duplicate a descriptor
duplicate a descriptor
lseek lseek – – change the current offsetchange the current offset
creat
creat
create/rewrite a named file
create/rewrite a named file
unlink
unlink
remove a directory entry
remove a directory entry
chmod
chmod : change permissions associated with file
: change permissions associated with file
fcntl
fcntl : file control
: file control
mmap
mmap : map file contents
: map file contents
We’ve seen
these in action
already
We’ll look at
these
15-213, F’ 02
open(path, O_WRONLY | O_CREAT | O_TRUNC, mode)
#include <fcntl.h>
int fd;
mode_t mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH;
char *filename = "/tmp/file";
fd = creat(filename, mode);
15-213, F’ 02
15-213, F’ 02
15-213, F’ 02
#include <fcntl.h>
int fcntl(int fd, int cmd, /* arg / ...); / Number of args depends on
cmd */
Make I/O synchronous or asynchronous
File locking
Receive signal when file is available for read/write
Receive signal when file is modified by another process
Keep file open across exec
Anything else a particular device driver needs to do
Find the lowest numbered available file descriptor greater than or
equal to arg and make it be a copy of fd
Compare to dup2 system call
dup2 returns the named descriptor and will close the named descriptor
if it was in use before the call
15-213, F’ 02
You want to do this using a Linux kernel
Ability to run many processes, do I/O, handle interrupts, etc
Really exercise the system, not just individual CPU tests in isolation
There are things you need to do in supervisor mode
You don ’ t want to rewrite the Linux kernel or define a new system
call interface
dynamically linked to the kernel at run time
Open this “device” as a file, and you can do fcntl on it
Individual supervisor mode operations can be fcntl commands
Can be multi-process, multi-threaded, do I/O, do whatever you want
with memory
System calls to do small, specific operations
15-213, F’ 02
mmap() maps a file into your memory space.
mmap() maps a file into your memory space.
Instead of a read/write paradigm, you use a memory
Instead of a read/write paradigm, you use a memory
access paradigm.
access paradigm.
What does this buy you?
What does this buy you?
Does it improve performance by avoiding the overhead
Does it improve performance by avoiding the overhead
of system calls?
of system calls?
15-213, F’ 02
15-213, F’ 02
dirp
dirp
struct dirent
long d_ino; / inode number /
off_t d_off; / offset to this dirent /
unsigned short d_reclen; / length of this d_name /
char d_name [NAME_MAX+1]; / file name (null-terminated) /
15-213, F’ 02
15-213, F’ 02
15-213, F’ 02
malloc
calloc
realloc
free
alloca
Kernel Virtual Memory
User Stack
(created at run time)
Unused
Kernel Virtual Memory
User Stack
(created at run time)
Shared Libraries
(memory mapped)
Run-time Heap
(created at run time)
Read-only code and data
Read/write data
0xffffffff
0xc
0x
0x