Lecture 1: Programming interface

Preparation

Questions from last lecture

Overview

Example: hello

$ strace -- echo hello

output:

execve("./a.out", ["./a.out"], [/* 23 vars */]) = 0
...
write(1, "hello\n", 6)                          = 6
...
exit_group(0)                                   = ?

Example: uptime

$ strace -- uptime

output:

execve("/usr/bin/uptime", ["uptime"], [/* 23 vars */]) = 0
...
open("/proc/uptime", O_RDONLY)                         = 3
lseek(3, 0, SEEK_SET)                                  = 0
read(3, "1244101.16 14920448.20\n", 2047)              = 23
...
exit_group(0)                                          = ?

Example: sh and uptime

$ strace -f -- sh -c uptime

output:

execve("/bin/sh", ["sh", "-c", "uptime"], [/* 23 vars */]) = 0
...
clone(child_stack=0, flags=CLONE_CHILD_CLEARTID|CLONE_CHILD_SETTID|SIGCHLD, child_tidptr=0x7f831c8ac9d0) = 24844
wait4(-1,  <unfinished ...>
[pid 24844] execve("/usr/bin/uptime", ["uptime"], [/* 23 vars */]) = 0
[pid 24844] exit_group(0)               = ?
[pid 24844] +++ exited with 0 +++
<... wait4 resumed> [{WIFEXITED(s) && WEXITSTATUS(s) == 0}], 0, NULL) = 24844
...

Exercises

draw the system calls for the following

$ uptime | tr '[a-z]' '[A-Z]'
$ uptime > file

Summary & questions