strace/Beobachtung des Shell-Befehls "date"
Befehlsaufruf
Der folgende Befehl ruft strace für den Shell-Befehl date auf und protokolliert die Ausgabe in die Datei "logfile" im aktuellen Verzeichnis.
$ strace -o logfile date
Ausgabe
Die Ausgabe lautet wie folgt und wurde hier der Einfachheit halber mit einer Zeilennummerierung versehen:
1 execve("/bin/date", ["date"], [/* 42 vars */]) = 0
2 brk(0) = 0x9383000
3 access("/etc/ld.so.nohwcap", F_OK) = -1 ENOENT (No such file or directory)
4 mmap2(NULL, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0xb781c000
5 access("/etc/ld.so.preload", R_OK) = -1 ENOENT (No such file or directory)
6 open("/etc/ld.so.cache", O_RDONLY) = 3
7 fstat64(3, {st_mode=S_IFREG|0644, st_size=83275, ...}) = 0
8 mmap2(NULL, 83275, PROT_READ, MAP_PRIVATE, 3, 0) = 0xb7807000
9 close(3) = 0
10 access("/etc/ld.so.nohwcap", F_OK) = -1 ENOENT (No such file or directory)
11 open("/lib/tls/i686/cmov/librt.so.1", O_RDONLY) = 3
12 read(3, "\177ELF\1\1\1\0\0\0\0\0\0\0\0\0\3\0\3\0\1\0\0\0\300\30\0\0004\0\0\0"..., 512) = 512
13 fstat64(3, {st_mode=S_IFREG|0644, st_size=30684, ...}) = 0
14 mmap2(NULL, 33364, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x823000
15 mmap2(0x82a000, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x6) = 0x82a000
16 close(3) = 0
17 access("/etc/ld.so.nohwcap", F_OK) = -1 ENOENT (No such file or directory)
18 open("/lib/tls/i686/cmov/libc.so.6", O_RDONLY) = 3
19 read(3, "\177ELF\1\1\1\0\0\0\0\0\0\0\0\0\3\0\3\0\1\0\0\0000m\1\0004\0\0\0"..., 512) = 512
20 fstat64(3, {st_mode=S_IFREG|0755, st_size=1405508, ...}) = 0
21 mmap2(NULL, 1415592, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x34c000
22 mprotect(0x49f000, 4096, PROT_NONE) = 0
23 mmap2(0x4a0000, 12288, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x153) = 0x4a0000
24 mmap2(0x4a3000, 10664, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0x4a3000
25 close(3) = 0
26 access("/etc/ld.so.nohwcap", F_OK) = -1 ENOENT (No such file or directory)
27 open("/lib/tls/i686/cmov/libpthread.so.0", O_RDONLY) = 3
28 read(3, "\177ELF\1\1\1\0\0\0\0\0\0\0\0\0\3\0\3\0\1\0\0\0 J\0\0004\0\0\0"..., 512) = 512
29 fstat64(3, {st_mode=S_IFREG|0755, st_size=117086, ...}) = 0
30 mmap2(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0xb7806000
31 mmap2(NULL, 98792, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x195000
32 mmap2(0x1aa000, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x14) = 0x1aa000
33 mmap2(0x1ac000, 4584, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0x1ac000
34 close(3) = 0
35 mmap2(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0xb7805000
36 set_thread_area({entry_number:-1 -> 6, base_addr:0xb78056c0, limit:1048575, seg_32bit:1, contents:0, read_exec_only:0, limit_in_pages:1, seg_not_present:0, useable:1}) = 0
37 mprotect(0x1aa000, 4096, PROT_READ) = 0
38 mprotect(0x4a0000, 8192, PROT_READ) = 0
39 mprotect(0x82a000, 4096, PROT_READ) = 0
40 mprotect(0x8057000, 4096, PROT_READ) = 0
41 mprotect(0xea6000, 4096, PROT_READ) = 0
42 munmap(0xb7807000, 83275) = 0
43 set_tid_address(0xb7805728) = 1953
44 set_robust_list(0xb7805730, 0xc) = 0
45 futex(0xbfcda4b0, FUTEX_WAKE_PRIVATE, 1) = 0
46 futex(0xbfcda4b0, FUTEX_WAIT_BITSET_PRIVATE|FUTEX_CLOCK_REALTIME, 1, NULL, bfcda4c0) = -1 EAGAIN (Resource temporarily unavailable)
47 rt_sigaction(SIGRTMIN, {0x199410, [], SA_SIGINFO}, NULL, 8) = 0
48 rt_sigaction(SIGRT_1, {0x1998f0, [], SA_RESTART|SA_SIGINFO}, NULL, 8) = 0
49 rt_sigprocmask(SIG_UNBLOCK, [RTMIN RT_1], NULL, 8) = 0
50 getrlimit(RLIMIT_STACK, {rlim_cur=8192*1024, rlim_max=RLIM_INFINITY}) = 0
51 uname({sys="Linux", node="kanzler", ...}) = 0
52 brk(0) = 0x9383000
53 brk(0x93a4000) = 0x93a4000
54 open("/usr/lib/locale/locale-archive", O_RDONLY|O_LARGEFILE) = -1 ENOENT (No such file or directory)
55 open("/usr/share/locale/locale.alias", O_RDONLY) = 3
56 fstat64(3, {st_mode=S_IFREG|0644, st_size=2570, ...}) = 0
57 mmap2(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0xb781b000
58 read(3, "# Locale name alias data base.\n#"..., 4096) = 2570
59 read(3, "", 4096) = 0
60 close(3) = 0
61 munmap(0xb781b000, 4096) = 0
62 open("/usr/lib/locale/de_CH.utf8/LC_IDENTIFICATION", O_RDONLY) = 3
63 fstat64(3, {st_mode=S_IFREG|0644, st_size=353, ...}) = 0
64 mmap2(NULL, 353, PROT_READ, MAP_PRIVATE, 3, 0) = 0xb781b000
65 close(3) = 0
66 open("/usr/lib/gconv/gconv-modules.cache", O_RDONLY) = 3
67 fstat64(3, {st_mode=S_IFREG|0644, st_size=26048, ...}) = 0
68 mmap2(NULL, 26048, PROT_READ, MAP_SHARED, 3, 0) = 0xb7814000
69 close(3) = 0
70 futex(0x4a2a8c, FUTEX_WAKE_PRIVATE, 2147483647) = 0
71 open("/usr/lib/locale/de_CH.utf8/LC_MEASUREMENT", O_RDONLY) = 3
72 fstat64(3, {st_mode=S_IFREG|0644, st_size=23, ...}) = 0
73 mmap2(NULL, 23, PROT_READ, MAP_PRIVATE, 3, 0) = 0xb7813000
74 close(3) = 0
75 open("/usr/lib/locale/de_CH.utf8/LC_TELEPHONE", O_RDONLY) = 3
76 fstat64(3, {st_mode=S_IFREG|0644, st_size=49, ...}) = 0
77 mmap2(NULL, 49, PROT_READ, MAP_PRIVATE, 3, 0) = 0xb7812000
78 close(3) = 0
79 open("/usr/lib/locale/de_CH.utf8/LC_ADDRESS", O_RDONLY) = 3
80 fstat64(3, {st_mode=S_IFREG|0644, st_size=127, ...}) = 0
81 mmap2(NULL, 127, PROT_READ, MAP_PRIVATE, 3, 0) = 0xb7811000
82 close(3) = 0
83 open("/usr/lib/locale/de_CH.utf8/LC_NAME", O_RDONLY) = 3
84 fstat64(3, {st_mode=S_IFREG|0644, st_size=62, ...}) = 0
85 mmap2(NULL, 62, PROT_READ, MAP_PRIVATE, 3, 0) = 0xb7810000
86 close(3) = 0
87 open("/usr/lib/locale/de_CH.utf8/LC_PAPER", O_RDONLY) = 3
88 fstat64(3, {st_mode=S_IFREG|0644, st_size=34, ...}) = 0
89 mmap2(NULL, 34, PROT_READ, MAP_PRIVATE, 3, 0) = 0xb780f000
90 close(3) = 0
91 open("/usr/lib/locale/de_CH.utf8/LC_MESSAGES", O_RDONLY) = 3
92 fstat64(3, {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0
93 close(3) = 0
94 open("/usr/lib/locale/de_CH.utf8/LC_MESSAGES/SYS_LC_MESSAGES", O_RDONLY) = 3
95 fstat64(3, {st_mode=S_IFREG|0644, st_size=54, ...}) = 0
96 mmap2(NULL, 54, PROT_READ, MAP_PRIVATE, 3, 0) = 0xb780e000
97 close(3) = 0
98 open("/usr/lib/locale/de_CH.utf8/LC_MONETARY", O_RDONLY) = 3
99 fstat64(3, {st_mode=S_IFREG|0644, st_size=294, ...}) = 0
100 mmap2(NULL, 294, PROT_READ, MAP_PRIVATE, 3, 0) = 0xb780d000
101 close(3) = 0
102 open("/usr/lib/locale/de_CH.utf8/LC_COLLATE", O_RDONLY) = 3
103 fstat64(3, {st_mode=S_IFREG|0644, st_size=1170770, ...}) = 0
104 mmap2(NULL, 1170770, PROT_READ, MAP_PRIVATE, 3, 0) = 0xb76e7000
105 close(3) = 0
106 open("/usr/lib/locale/de_CH.utf8/LC_TIME", O_RDONLY) = 3
107 fstat64(3, {st_mode=S_IFREG|0644, st_size=2382, ...}) = 0
108 mmap2(NULL, 2382, PROT_READ, MAP_PRIVATE, 3, 0) = 0xb780c000
109 close(3) = 0
110 open("/usr/lib/locale/de_CH.utf8/LC_NUMERIC", O_RDONLY) = 3
111 fstat64(3, {st_mode=S_IFREG|0644, st_size=54, ...}) = 0
112 mmap2(NULL, 54, PROT_READ, MAP_PRIVATE, 3, 0) = 0xb780b000
113 close(3) = 0
114 open("/usr/lib/locale/de_CH.utf8/LC_CTYPE", O_RDONLY) = 3
115 fstat64(3, {st_mode=S_IFREG|0644, st_size=256484, ...}) = 0
116 mmap2(NULL, 256484, PROT_READ, MAP_PRIVATE, 3, 0) = 0xb76a8000
117 close(3) = 0
118 clock_gettime(CLOCK_REALTIME, {1290945848, 115169817}) = 0
119 open("/etc/localtime", O_RDONLY) = 3
120 fstat64(3, {st_mode=S_IFREG|0644, st_size=1892, ...}) = 0
121 fstat64(3, {st_mode=S_IFREG|0644, st_size=1892, ...}) = 0
122 mmap2(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0xb76a7000
123 read(3, "TZif2\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\4\0\0\0\4\0\0\0\0"..., 4096) = 1892
124 _llseek(3, -28, [1864], SEEK_CUR) = 0
125 read(3, "\nCET-1CEST,M3.5.0,M10.5.0/3\n", 4096) = 28
126 close(3) = 0
127 munmap(0xb76a7000, 4096) = 0
128 fstat64(1, {st_mode=S_IFCHR|0620, st_rdev=makedev(136, 1), ...}) = 0
129 mmap2(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0xb76a7000
130 write(1, "Son Nov 28 13:04:08 CET 2010\n", 29) = 29
131 close(1) = 0
132 munmap(0xb76a7000, 4096) = 0
133 close(2) = 0
134 exit_group(0) = ?
|
Erklärung
Zeile 1
Nach Aufruf von "strace date" ist zu sehen, dass die Programmdatei "/bin/date" über einen Systemaufruf von "execve()" gestartet wird.
Zeile 5
Der Kernel überträgt dem Program Loader die Aufgabe, für das Laden der benötigten Systembibliotheken zu sorgen. Zuerst kommen dabei die in der Umgebungsvariablen "LD_PRELOAD" genannten Bibliotheken zum Zuge, als nächstes die in der Umgebungsvariable "LD_LIBRARY_PATH" angegebenen Verzeichnisse sowie der Cache des Program Loaders ("/etc/ld.so.cache").
Zeile 11, 18, 27
"date" benötigt die Bibliotheken "librt.so.1", "libc.so.6" (also die Glibc) und "libpthread.so.0" - das kann auch das Programm ldd herausfinden:
$ ldd $(which date) linux-gate.so.1 => (0x00fd1000) librt.so.1 => /lib/tls/i686/cmov/librt.so.1 (0x00929000) libc.so.6 => /lib/tls/i686/cmov/libc.so.6 (0x00614000) libpthread.so.0 => /lib/tls/i686/cmov/libpthread.so.0 (0x00474000) /lib/ld-linux.so.2 (0x00abb000)
Zeile 118
Nach dem Laden und Initialisieren sämtlicher Bibliotheken ruft "date" den Systemaufruf "clock_gettime()" auf, um den aktuellen Zeitpunkt zu bestimmen.
Zeile 119-126
Mit Hilfe der Zeitzonen-Daten kann "date" das Datum und die Uhrzeit ausgeben.
Zeile 130
"date" schreibt den Text auf den mit dem Dateideskriptor 1 verbundenen Standardausgabekanal.