Exercise 2
System Calls
In this exercise, we will gather information about the following commands:
rm, mv, chmod, chown, mkdir, rmdir, kill, ln, sleep, wget
(You might need to install wget on your machine.)
Description
| Command | Description |
|---|---|
rm |
remove files or directories |
mv |
move (rename) files |
chmod |
change file mode bits |
chown |
change file owner and group |
mkdir |
make directories |
rmdir |
remove empty directories |
kill |
send a signal to a process |
ln |
make links between files |
sleep |
delay for a specified amount of time |
wget |
non-interactive network downloader |
Path
Installation path using the which command:
| Command | Path |
|---|---|
rm |
/usr/bin/rm |
mv |
/usr/bin/mv |
chmod |
/usr/bin/chmod |
chown |
/usr/bin/chown |
mkdir |
/usr/bin/mkdir |
rmdir |
/usr/bin/rmdir |
kill |
/usr/bin/kill |
ln |
/usr/bin/ln |
sleep |
/usr/bin/sleep |
wget |
/usr/bin/wget |
(Programs in /bin and /usr/bin are part of the base installation of the operating system.)
Example
| Command | Example |
|---|---|
rm |
rm testfile.txt |
mv |
mv oldfile.txt newfile.txt |
chmod |
chmod 755 script.sh |
chown |
chown user:group file.txt |
mkdir |
mkdir newdir |
rmdir |
rmdir olddir |
kill |
kill 1234 |
ln |
ln -s /path/to/original /path/to/link |
sleep |
sleep 10 |
wget |
wget http://example.com/file.txt |
Characteristic System Calls
The system calls can be displayed using the following commands:
-
ktraceandkdump(BSD) -
strace(Linux)
The characteristic system calls usually appear relatively near the end of the output because libraries are loaded and conditions are checked beforehand.
| Command | System Calls |
|---|---|
rm |
unlink() (files), rmdir (empty directories) |
mv |
rename() (source and destination on the same filesystem), link/unlink (across different filesystems) |
chmod |
chmod() |
chown |
chown() |
mkdir |
mkdir() |
rmdir |
rmdir() |
kill |
kill() |
ln |
link (for hard links), symlink (for symbolic links) |
sleep |
nanosleep() |
wget |
socket(), connect() |