source is not readily available since they do not need to be recompiled in order to trace them. Students, hackers and the overly-curious will find that a great deal can be learned about a system and its system calls by tracing even ordinary programs. And programmers will find that since system calls and signals are events that happen at the user/kernel interface, a close examination of this boundary is very useful for bug isolation, sanity checking and attempting to capture race conditions. Each line in the trace contains the system call name, followed by its arguments in parentheses and its return value. An example from stracing the command "cat /dev/null" is: open("/dev/null", O_RDONLY) = 3 Errors (typically a return value of -1) have the errno symbol and error string appended. open("/foo/bar", O_RDONLY) = -1 ENOENT (No such file or directory) Signals are printed as signal symbol and decoded siginfo structure. An excerpt from stracing and interrupting the command "sleep 666" is: sigsuspend([] <unfinished ...> --- SIGINT {si_signo=SIGINT, si_code=SI_USER, si_pid=...} --- +++ killed by SIGINT +++ If a system call is being executed and meanwhile another one is being called from a different thread/process then strace will try to preserve the order of those events and mark the ongoing call as being unfinished. When the call returns it will be marked as resumed. [pid 28772] select(4, [3], NULL, NULL, NULL <unfinished ...> [pid 28779] clock_gettime(CLOCK_REALTIME, {1130322148, 939977000}) = 0 [pid 28772] <... select resumed> ) = 1 (in [3]) Interruption of a (restartable) system call by a signal delivery is processed differently as kernel terminates the system call and also arranges its immediate reexecution after the signal handler completes. read(0, 0x7ffff72cf5cf, 1) = ? ERESTARTSYS (To be restarted) --- SIGALRM ... --- rt_sigreturn(0xe) = 0 read(0, "", 1) = 0 Arguments are printed in symbolic form with passion. This example shows the shell performing ">>xyzzy" output redirection: open("xyzzy", O_WRONLY|O_APPEND|O_CREAT, 0666) = 3 Here, the second and the third argument of open(2) are decoded by breaking down the flag argument into its three bitwise-OR constituents and printing the mode value in octal by tradition. Where the traditional or native usage differs from ANSI or POSIX, the latter forms are preferred. In some cases, strace output is proven to be more readable than the source. Structure pointers are dereferenced and the members are displayed as appropriate. In most cases, arguments are formatted in the most C-like fashion possible. For example, the essence of the com‐ mand "ls -l /dev/null" is captured as: lstat("/dev/null", {st_mode=S_IFCHR|0666, st_rdev=makedev(0x1, 0x3), ...}) = 0 Notice how the 'struct stat' argument is dereferenced and how each member is displayed symbolically. In particular, observe how the st_mode member is carefully decoded into a bitwise-OR of symbolic and numeric values. Also notice in this example that the first argument to lstat(2) is an input to the system call and the second argument is an output. Since output arguments are not modified if the system call fails, arguments may not always be dereferenced. For example, retrying the "ls -l" example with a non-existent file produces the following line: lstat("/foo/bar", 0xb004) = -1 ENOENT (No such file or directory) Manual page strace(1) line 17 (press h for help or q to quit)
kihei/i-01b77bb37a0d39570
by SadServersMore by SadServers
total 5250172 drwxr-xr-x 7 admin admin 4096 Feb 7 20:00 . drwxr-xr-x 3 root root 4096 Sep 17 2023 .. drwx------ 3 admin admin 4096 Sep 17 2023 .ansible -rw-r--r-- 1 admin admin 220 Aug 4 2021 .bash_logout -rw-r--r-- 1 admin admin 3526 Aug 4 2021 .bashrc drwxr-xr-x 3 admin admin 4096 Feb 7 19:55 .config -rw-r--r-- 1 admin admin 807 Aug 4 2021 .profile drwx------ 2 admin admin 4096 Sep 17 2023 .ssh drwxr-xr-x 2 admin root 4096 Sep 17 2023 agent drwxr-xr-x 2 admin root 4096 Feb 7 20:00 data -rw-r--r-- 1 admin admin 5368709120 Feb 7 19:57 datafile -rw-r--r-- 1 admin admin 5210219 Sep 17 2023 datafile.gz -rwxr-xr-x 1 admin root 2207109 Sep 17 2023 kihei admin@i-0e30ea8b74f198298:~$ .
kihei/i-0e30ea8b74f198298 02:41
by SadServersadmin@i-0ead36c6be7f7d974:~$ ls -s data total 0 0 kihei admin@i-0ead36c6be7f7d974:~$ df -h Filesystem Size Used Avail Use% Mounted on udev 217M 0 217M 0% /dev tmpfs 46M 368K 46M 1% /run /dev/nvme0n1p1 7.7G 6.1G 1.2G 84% / tmpfs 228M 12K 228M 1% /dev/shm tmpfs 5.0M 0 5.0M 0% /run/lock /dev/nvme0n1p15 124M 5.9M 118M 5% /boot/efi tmpfs 2.0G 0 2.0G 0% /tmp/kihei admin@i-0ead36c6be7f7d974:~$ ln -s /tmp/kihei/ /home/admin/data ln: failed to create symbolic link '/home/admin/data/kihei': File exists admin@i-0ead36c6be7f7d974:~$ mo
kihei/i-0ead36c6be7f7d974 03:05
by SadServers│ └─594 /sbin/agetty -o -p -- \u --noclear tty1 linux ├─systemd-logind.service │ └─585 /lib/systemd/systemd-logind └─gotty.service ├─565 /usr/local/gotty --permit-write --reconnect --max-connectio ├─690 bash -l ├─695 /usr/bin/python3 /usr/bin/asciinema rec -t paris/i-0541fd78og/cast/i-0541fd782d91559ca ├─698 /usr/bin/python3 /usr/bin/asciinema rec -t paris/i-0541fd78og/cast/i-0541fd782d91559ca ├─699 sh -c /bin/bash ├─700 /bin/bash ├─982 systemctl status └─983 less admin@i-0541fd782d91559ca:~$