#yakit
UNIX *nix
strace ltrace
-
UNIX
1969 (AT&T/Bell Labs: , , )
- - (POSIX)
AIX, Solaris, Mac OS X/FreeBSD/NetBSD/OpenBSD
UNIX
Linux, Minix
POSIX Windows
*nix
6
*nix =
Runtime
Shell
Java
Perl/Python/PHP/...
10
(, IPC, , )
11
?
ABI - syscalls
mov edx,len
mov
ecx,msg
mov
ebx,1
mov
eax,4
(sys_write)
int
0x80
mov eax,1
int
section .data
msg db
len
12
'Hello, world!',0xa
equ $ - msg
13
?
ABI - syscalls
int main() {
__asm__(
"movl $20, %eax \n"
"call *%gs:0x10 \n"
"movl %eax, pid \n"
);
printf("pid is %d\n", pid);
return 0;
}
14
C?
ABI - syscalls
#include <unistd.h>
/* ... */
const char msg[] = "Hello world";
write( STDOUT_FILENO, msg, sizeof(
msg ) - 1 );
/* write
syscall? */
15
ltrace
strace
16
Shell: /bin/*sh
*nix
While (1) {
write (1, "$ ", 2);
readcmd (cmd, args);
// parse user input
if ((pid = fork ()) == 0) { // child?
exec (cmd, args, 0);
} else if (pid > 0) {
// parent?
wait (0);
// wait for child to terminate
} else {
perror ("fork");
}
}
17
:
: read, write, fork,
exec, wait
:
-1
errno
perror
errno
18
: fork
,
:
(, , )
: , ,
:
PID
fork
0
pid
19
: exec
(
pid, uid, )
20
: wait
?
wait?
21
fork/exec
?
ls ,
stdin, stdout?
cwd
Copy-on-write fork
22
: read/write
:
23
?
*nix, Windows NT
24
:
:
25
:
?
()
?
, ,
26
vmstat
cat /proc/1/status
ps
27
?
man ps
/STATE
28
:
: :
2^32
? .
29
90-
x86
CS, DS
4
copy-on-write fork
30
vmstat
cat /proc/swaps
swapon -s
31
( )
32
:
(Windows 3.1, Mac OS 9, WOW16)
(preemptive)
33
batch
BSD:
Android:
34
FIFO/FCFS
SJF (Shortest Job First)
()
Round-Robin
CFQ
35
(sharing)
()
()
36
-
:
-
37
-
:
(RSS)
FIFO/FCFS
LIFO
CFQ
SCAN ()
Noop (FIFO )
Anticipatory ()
Deadline (
38
...
LRU
...
39
Operation
Time (nsec)
L2 cache reference 7
Mutex lock/unlock 25
Main memory reference
100
3,000
20,000
250,000
Disk seek
10,000,000
150,000,000
Operation
Time (nsec)
3000
41
119021, , ,
. , . 16.
+7 (495) 739-70-00
+7 (495) 739-70-70
vashik@yandex-team.ru