0x1000_0000
0x1000_0000
)
user/user.h
for system calls$ strace -o log -- echo hello
output:
execve("/usr/bin/echo", ["echo", "hello"], [/* 43 vars */]) = 0
...
write(1, "hello\n", 6) = 6
...
exit_group(0) = ?
execve
(first), write
, exit_group
(last)write
exit_group
$ strace -o log -- uptime
output:
execve("/usr/bin/uptime", ["uptime"], [/* 43 vars */]) = 0
...
openat(AT_FDCWD, "/proc/uptime", O_RDONLY) = 3
lseek(3, 0, SEEK_SET) = 0
read(3, "8827716.99 421503180.64\n", 8191) = 24
...
write(1, " 15:37:50 up 102 days, 4:08, 8"..., 72) = 72
...
exit_group(0) = ?
open
/openat
, lseek
, read
, …/proc/uptime
- is this a real file on disk?
(source code)cat /proc/cpuinfo
; see more about procfscat /dev/random
what system calls are used to implement redirection >
(i.e., how does the output of uptime
go to an on-disk file instead of terminal)?
$ uptime > file
hints:
clone(...)
(old days: fork
).execve("/usr/bin/uptime", ...)
and the system calls right above (openat
, dup2
, close
).what system calls are used to implement pipe |
?
$ uptime | tr '[a-z]' '[A-Z]'
hints:
pipe
, clone
, execve
, and dup2
.strace
is implemented in Linux
exit
in main
? what if we simply return without calling exit
?+------+ +------+ +------+
| app1 | | app2 | | app3 |
+------+ +------+ +------+
+-------------------------------+
| operating system |
+-------------------------------+
+-----+ +-----+ +-------------+
| CPU | | RAM | | I/O devices |
+-----+ +-----+ +-------------+
kernel/start.c
kernel/memlayout.h
in xv6ecall
instructionsret
instruction