System Calls: Practical
Objectives
We would like to :
- Look at several unix/linux system calls.
Notes
- System calls are how the operating systems services are made available.
- This is part of the OS's API
- In the case of linux/unix they are c calls.
- The book discusses in theory a copy command.
- I want to do this in practice.
- See myCP.cpp.
- I did this in about an hour.
- And it most likely is not a very safe command.
- But it is a basic version of the system call cp
- Which is in /usr/bin/cp or /bin/cp
- ls -i /usr/bin/cp /bin/cp (discuss hard link, inode number)
- Some explicit system calls
-
open
, opens a file
-
close
, closes a file
-
read
, reads a set number of bytes from a file descriptor
-
write
, writes a set number of bytes to a file descriptor
- In general in UNIX/Linux
- System calls normally return -1 on error,
- But this is not set in stone.
- System calls set a global variable
errno
when an error occurs.
- But this very much must be managed by the user
- IE it is not reset after an error.
-
perror
is a library call that looks at errno and
- Watch this with
strace
- This uses the
ptrace
system call
- I have another program
- prio.cpp
- This is somewhat equivelent to nice/renice
- On Linux/UNIX processes have a "nice" level
- -19 to 20
- The lower, the more important the process is.
- Users can normally raise their nice level (ie be more nice, let other processes have the cpu)
- But they can't lower it.
- This does two different types of requests.
-
getrlimit
and getpriority
request information
-
setpriority
and nice
set values.
- run
nice -n 4 prio