Estando nessa categoria de usuários linux, eu também me fiz essa pergunta.
A primeira coisa que vem à mente é strace
( man page ).
Conhecer partes do kernel pode lhe dar uma ideia de como explicar a saída do strace e depurar seu código ainda mais a partir de seus logs regulares.
Por exemplo, esta é a saída de strace cat text.txt
, em que text.txt
contém a sentença my name is test
.
execve("/usr/bin/cat", ["cat", "test.txt"], [/* 76 vars */]) = 0
brk(0) = 0x1e4f000
mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f1b8ecd4000
open("/etc/ld.so.cache", O_RDONLY|O_CLOEXEC) = 3
fstat(3, {st_mode=S_IFREG|0644, st_size=138212, ...}) = 0
mmap(NULL, 138212, PROT_READ, MAP_PRIVATE, 3, 0) = 0x7f1b8ecb2000
close(3) = 0
open("/lib64/libc.so.6", O_RDONLY|O_CLOEXEC) = 3
read(3, "7ELFexecve("/usr/bin/cat", ["cat", "test.txt"], [/* 76 vars */]) = 0
brk(0) = 0x1e4f000
mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f1b8ecd4000
open("/etc/ld.so.cache", O_RDONLY|O_CLOEXEC) = 3
fstat(3, {st_mode=S_IFREG|0644, st_size=138212, ...}) = 0
mmap(NULL, 138212, PROT_READ, MAP_PRIVATE, 3, 0) = 0x7f1b8ecb2000
close(3) = 0
open("/lib64/libc.so.6", O_RDONLY|O_CLOEXEC) = 3
read(3, "7ELF%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%>%pre%%pre%%pre%%pre%@%pre%%pre%%pre%%pre%%pre%"..., 832) = 832
fstat(3, {st_mode=S_IFREG|0755, st_size=2118128, ...}) = 0
mmap(NULL, 3932672, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x7f1b8e6f5000
mprotect(0x7f1b8e8ab000, 2097152, PROT_NONE) = 0
mmap(0x7f1b8eaab000, 24576, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x1b6000) = 0x7f1b8eaab000
mmap(0x7f1b8eab1000, 16896, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0x7f1b8eab1000
close(3) = 0
mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f1b8ecb1000
mmap(NULL, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f1b8ecaf000
arch_prctl(ARCH_SET_FS, 0x7f1b8ecaf740) = 0
mprotect(0x7f1b8eaab000, 16384, PROT_READ) = 0
mprotect(0x60b000, 4096, PROT_READ) = 0
mprotect(0x7f1b8ecd5000, 4096, PROT_READ) = 0
munmap(0x7f1b8ecb2000, 138212) = 0
brk(0) = 0x1e4f000
brk(0x1e70000) = 0x1e70000
brk(0) = 0x1e70000
open("/usr/lib/locale/locale-archive", O_RDONLY|O_CLOEXEC) = 3
fstat(3, {st_mode=S_IFREG|0644, st_size=106070960, ...}) = 0
mmap(NULL, 106070960, PROT_READ, MAP_PRIVATE, 3, 0) = 0x7f1b881cc000
close(3) = 0
fstat(1, {st_mode=S_IFCHR|0620, st_rdev=makedev(136, 0), ...}) = 0
open("test.txt", O_RDONLY) = 3
fstat(3, {st_mode=S_IFREG|0664, st_size=16, ...}) = 0
fadvise64(3, 0, 0, POSIX_FADV_SEQUENTIAL) = 0
read(3, "my name is test\n", 65536) = 16
write(1, "my name is test\n", 16my name is test
) = 16
read(3, "", 65536) = 0
close(3) = 0
close(1) = 0
close(2) = 0
exit_group(0) = ?
+++ exited with 0 +++
%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%>%pre%%pre%%pre%%pre%@%pre%%pre%%pre%%pre%%pre%"..., 832) = 832
fstat(3, {st_mode=S_IFREG|0755, st_size=2118128, ...}) = 0
mmap(NULL, 3932672, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x7f1b8e6f5000
mprotect(0x7f1b8e8ab000, 2097152, PROT_NONE) = 0
mmap(0x7f1b8eaab000, 24576, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x1b6000) = 0x7f1b8eaab000
mmap(0x7f1b8eab1000, 16896, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0x7f1b8eab1000
close(3) = 0
mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f1b8ecb1000
mmap(NULL, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f1b8ecaf000
arch_prctl(ARCH_SET_FS, 0x7f1b8ecaf740) = 0
mprotect(0x7f1b8eaab000, 16384, PROT_READ) = 0
mprotect(0x60b000, 4096, PROT_READ) = 0
mprotect(0x7f1b8ecd5000, 4096, PROT_READ) = 0
munmap(0x7f1b8ecb2000, 138212) = 0
brk(0) = 0x1e4f000
brk(0x1e70000) = 0x1e70000
brk(0) = 0x1e70000
open("/usr/lib/locale/locale-archive", O_RDONLY|O_CLOEXEC) = 3
fstat(3, {st_mode=S_IFREG|0644, st_size=106070960, ...}) = 0
mmap(NULL, 106070960, PROT_READ, MAP_PRIVATE, 3, 0) = 0x7f1b881cc000
close(3) = 0
fstat(1, {st_mode=S_IFCHR|0620, st_rdev=makedev(136, 0), ...}) = 0
open("test.txt", O_RDONLY) = 3
fstat(3, {st_mode=S_IFREG|0664, st_size=16, ...}) = 0
fadvise64(3, 0, 0, POSIX_FADV_SEQUENTIAL) = 0
read(3, "my name is test\n", 65536) = 16
write(1, "my name is test\n", 16my name is test
) = 16
read(3, "", 65536) = 0
close(3) = 0
close(1) = 0
close(2) = 0
exit_group(0) = ?
+++ exited with 0 +++
Todas as chamadas do sistema são visíveis acima, portanto, se você tiver algum conhecimento do kernel, terá mais dicas Depurando seu código.