共享库是做什么用的,为什么 ls 需要加载这么多?
What do shared libraries do and why does ls need to load so many?
我一直在 ls 命令上使用 strace,我遇到了下面的大量文本,在做一些研究时我发现其中绝大多数是加载或读取共享库。我的问题是,用简单的初学者术语来说,什么是共享库,如果最后几行完成了我们需要做的所有事情,为什么 ls 需要这么多?
对于上下文,我试图解释像 ls 这样的简单过程从被调用到被终止的过程。
execve("/usr/bin/ls", ["ls"], 0x7ffeaa5999c0 /* 49 vars */) = 0
brk(NULL) = 0x5616fe4fa000
arch_prctl(0x3001 /* ARCH_??? */, 0x7ffc4fdc9040) = -1 EINVAL (Invalid argument)
access("/etc/ld.so.preload", R_OK) = -1 ENOENT (No such file or directory)
openat(AT_FDCWD, "/etc/ld.so.cache", O_RDONLY|O_CLOEXEC) = 3
fstat(3, {st_mode=S_IFREG|0644, st_size=58140, ...}) = 0
mmap(NULL, 58140, PROT_READ, MAP_PRIVATE, 3, 0) = 0x7f25a2a11000
close(3) = 0
openat(AT_FDCWD, "/lib/x86_64-linux-gnu/libselinux.so.1", O_RDONLY|O_CLOEXEC) = 3
read(3, "7ELF[=10=][=10=][=10=][=10=][=10=][=10=][=10=][=10=][=10=][=10=]>[=10=][=10=][=10=][=10=]@p[=10=][=10=][=10=][=10=][=10=][=10=]"..., 832) = 832
fstat(3, {st_mode=S_IFREG|0644, st_size=163200, ...}) = 0
mmap(NULL, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f25a2a0f000
mmap(NULL, 174600, PROT_READ, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x7f25a29e4000
mprotect(0x7f25a29ea000, 135168, PROT_NONE) = 0
mmap(0x7f25a29ea000, 102400, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x6000) = 0x7f25a29ea000
mmap(0x7f25a2a03000, 28672, PROT_READ, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x1f000) = 0x7f25a2a03000
mmap(0x7f25a2a0b000, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x26000) = 0x7f25a2a0b000
mmap(0x7f25a2a0d000, 6664, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0x7f25a2a0d000
close(3) = 0
openat(AT_FDCWD, "/lib/x86_64-linux-gnu/libc.so.6", O_RDONLY|O_CLOEXEC) = 3
read(3, "7ELF[=10=][=10=][=10=][=10=][=10=][=10=][=10=][=10=][=10=]>[=10=][=10=][=10=][=10=]0A[=10=][=10=][=10=][=10=][=10=]"..., 832) = 832
pread64(3, "[=10=][=10=][=10=][=10=][=10=][=10=]@[=10=][=10=][=10=][=10=][=10=][=10=][=10=]@[=10=][=10=][=10=][=10=][=10=][=10=][=10=]@[=10=][=10=][=10=][=10=][=10=][=10=][=10=]"..., 784, 64) = 784
pread64(3, "[=10=][=10=][=10=][=10=][=10=][=10=][=10=][=10=][=10=]GNU[=10=][=10=][=10=]0[=10=][=10=][=10=][=10=][=10=][=10=][=10=][=10=][=10=][=10=]", 32, 848) = 32
pread64(3, "[=10=][=10=][=10=][=10=][=10=][=10=][=10=][=10=][=10=]GNU[=10=]73t720l3*2C0T7"..., 68, 880) = 68
fstat(3, {st_mode=S_IFREG|0755, st_size=2029560, ...}) = 0
pread64(3, "[=10=][=10=][=10=][=10=][=10=][=10=]@[=10=][=10=][=10=][=10=][=10=][=10=][=10=]@[=10=][=10=][=10=][=10=][=10=][=10=][=10=]@[=10=][=10=][=10=][=10=][=10=][=10=][=10=]"..., 784, 64) = 784
pread64(3, "[=10=][=10=][=10=][=10=][=10=][=10=][=10=][=10=][=10=]GNU[=10=][=10=][=10=]0[=10=][=10=][=10=][=10=][=10=][=10=][=10=][=10=][=10=][=10=]", 32, 848) = 32
pread64(3, "[=10=][=10=][=10=][=10=][=10=][=10=][=10=][=10=][=10=]GNU[=10=]73t720l3*2C0T7"..., 68, 880) = 68
mmap(NULL, 2037344, PROT_READ, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x7f25a27f2000
mmap(0x7f25a2814000, 1540096, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x22000) = 0x7f25a2814000
mmap(0x7f25a298c000, 319488, PROT_READ, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x19a000) = 0x7f25a298c000
mmap(0x7f25a29da000, 24576, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x1e7000) = 0x7f25a29da000
mmap(0x7f25a29e0000, 13920, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0x7f25a29e0000
close(3) = 0
openat(AT_FDCWD, "/lib/x86_64-linux-gnu/libpcre2-8.so.0", O_RDONLY|O_CLOEXEC) = 3
read(3, "7ELF[=10=][=10=][=10=][=10=][=10=][=10=][=10=][=10=][=10=][=10=]>[=10=][=10=][=10=][=10=]0\"[=10=][=10=][=10=][=10=][=10=][=10=]"..., 832) = 832
fstat(3, {st_mode=S_IFREG|0644, st_size=584392, ...}) = 0
mmap(NULL, 586536, PROT_READ, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x7f25a2762000
mmap(0x7f25a2764000, 409600, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x2000) = 0x7f25a2764000
mmap(0x7f25a27c8000, 163840, PROT_READ, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x66000) = 0x7f25a27c8000
mmap(0x7f25a27f0000, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x8d000) = 0x7f25a27f0000
close(3) = 0
openat(AT_FDCWD, "/lib/x86_64-linux-gnu/libdl.so.2", O_RDONLY|O_CLOEXEC) = 3
read(3, "7ELF[=10=][=10=][=10=][=10=][=10=][=10=][=10=][=10=][=10=][=10=]>[=10=][=10=][=10=][=10=] [=10=][=10=][=10=][=10=][=10=][=10=]"..., 832) = 832
fstat(3, {st_mode=S_IFREG|0644, st_size=18816, ...}) = 0
mmap(NULL, 20752, PROT_READ, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x7f25a275c000
mmap(0x7f25a275d000, 8192, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x1000) = 0x7f25a275d000
mmap(0x7f25a275f000, 4096, PROT_READ, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x3000) = 0x7f25a275f000
mmap(0x7f25a2760000, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x3000) = 0x7f25a2760000
close(3) = 0
openat(AT_FDCWD, "/lib/x86_64-linux-gnu/libpthread.so.0", O_RDONLY|O_CLOEXEC) = 3
read(3, "7ELF[=10=][=10=][=10=][=10=][=10=][=10=][=10=][=10=][=10=][=10=]>[=10=][=10=][=10=][=10=]0q[=10=][=10=][=10=][=10=][=10=][=10=]"..., 832) = 832
pread64(3, "[=10=][=10=][=10=][=10=][=10=][=10=][=10=][=10=][=10=]GNU[=10=]000%003'62u/476u"..., 68, 824) = 68
fstat(3, {st_mode=S_IFREG|0755, st_size=157224, ...}) = 0
pread64(3, "[=10=][=10=][=10=][=10=][=10=][=10=][=10=][=10=][=10=]GNU[=10=]000%003'62u/476u"..., 68, 824) = 68
mmap(NULL, 140408, PROT_READ, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x7f25a2739000
mmap(0x7f25a273f000, 69632, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x6000) = 0x7f25a273f000
mmap(0x7f25a2750000, 24576, PROT_READ, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x17000) = 0x7f25a2750000
mmap(0x7f25a2756000, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x1c000) = 0x7f25a2756000
mmap(0x7f25a2758000, 13432, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0x7f25a2758000
close(3) = 0
mmap(NULL, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f25a2737000
arch_prctl(ARCH_SET_FS, 0x7f25a2738400) = 0 mprotect(0x7f25a29da000, 16384, PROT_READ) = 0 mprotect(0x7f25a2756000, 4096, PROT_READ) = 0
mprotect(0x7f25a2760000, 4096, PROT_READ) = 0
mprotect(0x7f25a27f0000, 4096, PROT_READ) = 0
mprotect(0x7f25a2a0b000, 4096, PROT_READ) = 0 mprotect(0x5616fca52000, 4096, PROT_READ) = 0 mprotect(0x7f25a2a4d000, 4096, PROT_READ) = 0
munmap(0x7f25a2a11000, 58140) = 0
set_tid_address(0x7f25a27386d0) = 1376
set_robust_list(0x7f25a27386e0, 24) = 0
rt_sigaction(SIGRTMIN, {sa_handler=0x7f25a273fbf0, sa_mask=[], sa_flags=SA_RESTORER|SA_SIGINFO, sa_restorer=0x7f25a274d3c0}, NULL, 8) = 0
rt_sigaction(SIGRT_1, {sa_handler=0x7f25a273fc90, sa_mask=[], sa_flags=SA_RESTORER|SA_RESTART|SA_SIGINFO, sa_restorer=0x7f25a274d3c0}, NULL, 8) = 0
rt_sigprocmask(SIG_UNBLOCK, [RTMIN RT_1], NULL, 8) = 0
prlimit64(0, RLIMIT_STACK, NULL, {rlim_cur=8192*1024, rlim_max=RLIM64_INFINITY}) = 0
statfs("/sys/fs/selinux", 0x7ffc4fdc8f90) = -1 ENOENT (No such file or directory)
statfs("/selinux", 0x7ffc4fdc8f90) = -1 ENOENT (No such file or directory)
brk(NULL) = 0x5616fe4fa000
brk(0x5616fe51b000) = 0x5616fe51b000
openat(AT_FDCWD, "/proc/filesystems", O_RDONLY|O_CLOEXEC) = 3
fstat(3, {st_mode=S_IFREG|0444, st_size=0, ...}) = 0
read(3, "nodev\tsysfs\nnodev\ttmpfs\nnodev\tbd"..., 1024) = 360
read(3, "", 1024) = 0 close(3) = 0
access("/etc/selinux/config", F_OK) = -1 ENOENT (No such file or directory)
openat(AT_FDCWD, "/usr/lib/locale/locale-archive", O_RDONLY|O_CLOEXEC) = 3
fstat(3, {st_mode=S_IFREG|0644, st_size=5699248, ...}) = 0
mmap(NULL, 5699248, PROT_READ, MAP_PRIVATE, 3, 0) = 0x7f25a21c7000
close(3) = 0
ioctl(1, TCGETS, {B38400 opost isig icanon echo ...}) = 0
ioctl(1, TIOCGWINSZ, {ws_row=24, ws_col=80, ws_xpixel=0, ws_ypixel=0}) = 0
openat(AT_FDCWD, ".", O_RDONLY|O_NONBLOCK|O_CLOEXEC|O_DIRECTORY) = 3
fstat(3, {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0
getdents64(3, /* 20 entries */, 32768) = 624 getdents64(3, /* 0 entries */, 32768) = 0
close(3) = 0
fstat(1, {st_mode=S_IFCHR|0620, st_rdev=makedev(0x88, 0), ...}) = 0
write(1, "Desktop Documents Downloads M"..., 72Desktop Documents Downloads Music Pictures Public Templates Videos ) = 72
close(1) = 0 close(2) = 0
exit_group(0) = ? +++ exited with 0 +++
in simple beginner terms, what are shared libraries
共享库允许
- 二进制文件共享通用代码,因此您不会在磁盘和 RAM 中存储 1000 多个单独的
printf
代码实例,并且
- 允许错误修复同时影响所有二进制文件。
(1) 在磁盘为 10MiB 而 64KiB 是 lot RAM 时曾经很重要,但现在这个原因的重要性已经降低。
(2) 的重要性已显着增加——在单个系统上有 1000 多个二进制文件,将它们全部重建是不切实际的(如果不是共享库,这将是 bug 修复生效所必需的)。
and why does ls need so many
它只使用了几个库:libc.so.6
、libdl.so.2
和libpthread.so.0
、libselinux.so.1
和libpcre2-8.so.0
.为了比较,firefox
或 google-chrome
使用 90+,而我使用的一些二进制文件使用 10,000+。
ls
不一定是一个简单的程序 -- 它可以做颜色,它可以在多个语言环境中显示和排序文件名等。
我一直在 ls 命令上使用 strace,我遇到了下面的大量文本,在做一些研究时我发现其中绝大多数是加载或读取共享库。我的问题是,用简单的初学者术语来说,什么是共享库,如果最后几行完成了我们需要做的所有事情,为什么 ls 需要这么多?
对于上下文,我试图解释像 ls 这样的简单过程从被调用到被终止的过程。
execve("/usr/bin/ls", ["ls"], 0x7ffeaa5999c0 /* 49 vars */) = 0
brk(NULL) = 0x5616fe4fa000
arch_prctl(0x3001 /* ARCH_??? */, 0x7ffc4fdc9040) = -1 EINVAL (Invalid argument)
access("/etc/ld.so.preload", R_OK) = -1 ENOENT (No such file or directory)
openat(AT_FDCWD, "/etc/ld.so.cache", O_RDONLY|O_CLOEXEC) = 3
fstat(3, {st_mode=S_IFREG|0644, st_size=58140, ...}) = 0
mmap(NULL, 58140, PROT_READ, MAP_PRIVATE, 3, 0) = 0x7f25a2a11000
close(3) = 0
openat(AT_FDCWD, "/lib/x86_64-linux-gnu/libselinux.so.1", O_RDONLY|O_CLOEXEC) = 3
read(3, "7ELF[=10=][=10=][=10=][=10=][=10=][=10=][=10=][=10=][=10=][=10=]>[=10=][=10=][=10=][=10=]@p[=10=][=10=][=10=][=10=][=10=][=10=]"..., 832) = 832
fstat(3, {st_mode=S_IFREG|0644, st_size=163200, ...}) = 0
mmap(NULL, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f25a2a0f000
mmap(NULL, 174600, PROT_READ, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x7f25a29e4000
mprotect(0x7f25a29ea000, 135168, PROT_NONE) = 0
mmap(0x7f25a29ea000, 102400, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x6000) = 0x7f25a29ea000
mmap(0x7f25a2a03000, 28672, PROT_READ, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x1f000) = 0x7f25a2a03000
mmap(0x7f25a2a0b000, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x26000) = 0x7f25a2a0b000
mmap(0x7f25a2a0d000, 6664, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0x7f25a2a0d000
close(3) = 0
openat(AT_FDCWD, "/lib/x86_64-linux-gnu/libc.so.6", O_RDONLY|O_CLOEXEC) = 3
read(3, "7ELF[=10=][=10=][=10=][=10=][=10=][=10=][=10=][=10=][=10=]>[=10=][=10=][=10=][=10=]0A[=10=][=10=][=10=][=10=][=10=]"..., 832) = 832
pread64(3, "[=10=][=10=][=10=][=10=][=10=][=10=]@[=10=][=10=][=10=][=10=][=10=][=10=][=10=]@[=10=][=10=][=10=][=10=][=10=][=10=][=10=]@[=10=][=10=][=10=][=10=][=10=][=10=][=10=]"..., 784, 64) = 784
pread64(3, "[=10=][=10=][=10=][=10=][=10=][=10=][=10=][=10=][=10=]GNU[=10=][=10=][=10=]0[=10=][=10=][=10=][=10=][=10=][=10=][=10=][=10=][=10=][=10=]", 32, 848) = 32
pread64(3, "[=10=][=10=][=10=][=10=][=10=][=10=][=10=][=10=][=10=]GNU[=10=]73t720l3*2C0T7"..., 68, 880) = 68
fstat(3, {st_mode=S_IFREG|0755, st_size=2029560, ...}) = 0
pread64(3, "[=10=][=10=][=10=][=10=][=10=][=10=]@[=10=][=10=][=10=][=10=][=10=][=10=][=10=]@[=10=][=10=][=10=][=10=][=10=][=10=][=10=]@[=10=][=10=][=10=][=10=][=10=][=10=][=10=]"..., 784, 64) = 784
pread64(3, "[=10=][=10=][=10=][=10=][=10=][=10=][=10=][=10=][=10=]GNU[=10=][=10=][=10=]0[=10=][=10=][=10=][=10=][=10=][=10=][=10=][=10=][=10=][=10=]", 32, 848) = 32
pread64(3, "[=10=][=10=][=10=][=10=][=10=][=10=][=10=][=10=][=10=]GNU[=10=]73t720l3*2C0T7"..., 68, 880) = 68
mmap(NULL, 2037344, PROT_READ, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x7f25a27f2000
mmap(0x7f25a2814000, 1540096, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x22000) = 0x7f25a2814000
mmap(0x7f25a298c000, 319488, PROT_READ, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x19a000) = 0x7f25a298c000
mmap(0x7f25a29da000, 24576, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x1e7000) = 0x7f25a29da000
mmap(0x7f25a29e0000, 13920, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0x7f25a29e0000
close(3) = 0
openat(AT_FDCWD, "/lib/x86_64-linux-gnu/libpcre2-8.so.0", O_RDONLY|O_CLOEXEC) = 3
read(3, "7ELF[=10=][=10=][=10=][=10=][=10=][=10=][=10=][=10=][=10=][=10=]>[=10=][=10=][=10=][=10=]0\"[=10=][=10=][=10=][=10=][=10=][=10=]"..., 832) = 832
fstat(3, {st_mode=S_IFREG|0644, st_size=584392, ...}) = 0
mmap(NULL, 586536, PROT_READ, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x7f25a2762000
mmap(0x7f25a2764000, 409600, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x2000) = 0x7f25a2764000
mmap(0x7f25a27c8000, 163840, PROT_READ, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x66000) = 0x7f25a27c8000
mmap(0x7f25a27f0000, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x8d000) = 0x7f25a27f0000
close(3) = 0
openat(AT_FDCWD, "/lib/x86_64-linux-gnu/libdl.so.2", O_RDONLY|O_CLOEXEC) = 3
read(3, "7ELF[=10=][=10=][=10=][=10=][=10=][=10=][=10=][=10=][=10=][=10=]>[=10=][=10=][=10=][=10=] [=10=][=10=][=10=][=10=][=10=][=10=]"..., 832) = 832
fstat(3, {st_mode=S_IFREG|0644, st_size=18816, ...}) = 0
mmap(NULL, 20752, PROT_READ, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x7f25a275c000
mmap(0x7f25a275d000, 8192, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x1000) = 0x7f25a275d000
mmap(0x7f25a275f000, 4096, PROT_READ, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x3000) = 0x7f25a275f000
mmap(0x7f25a2760000, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x3000) = 0x7f25a2760000
close(3) = 0
openat(AT_FDCWD, "/lib/x86_64-linux-gnu/libpthread.so.0", O_RDONLY|O_CLOEXEC) = 3
read(3, "7ELF[=10=][=10=][=10=][=10=][=10=][=10=][=10=][=10=][=10=][=10=]>[=10=][=10=][=10=][=10=]0q[=10=][=10=][=10=][=10=][=10=][=10=]"..., 832) = 832
pread64(3, "[=10=][=10=][=10=][=10=][=10=][=10=][=10=][=10=][=10=]GNU[=10=]000%003'62u/476u"..., 68, 824) = 68
fstat(3, {st_mode=S_IFREG|0755, st_size=157224, ...}) = 0
pread64(3, "[=10=][=10=][=10=][=10=][=10=][=10=][=10=][=10=][=10=]GNU[=10=]000%003'62u/476u"..., 68, 824) = 68
mmap(NULL, 140408, PROT_READ, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x7f25a2739000
mmap(0x7f25a273f000, 69632, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x6000) = 0x7f25a273f000
mmap(0x7f25a2750000, 24576, PROT_READ, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x17000) = 0x7f25a2750000
mmap(0x7f25a2756000, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x1c000) = 0x7f25a2756000
mmap(0x7f25a2758000, 13432, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0x7f25a2758000
close(3) = 0
mmap(NULL, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f25a2737000
arch_prctl(ARCH_SET_FS, 0x7f25a2738400) = 0 mprotect(0x7f25a29da000, 16384, PROT_READ) = 0 mprotect(0x7f25a2756000, 4096, PROT_READ) = 0
mprotect(0x7f25a2760000, 4096, PROT_READ) = 0
mprotect(0x7f25a27f0000, 4096, PROT_READ) = 0
mprotect(0x7f25a2a0b000, 4096, PROT_READ) = 0 mprotect(0x5616fca52000, 4096, PROT_READ) = 0 mprotect(0x7f25a2a4d000, 4096, PROT_READ) = 0
munmap(0x7f25a2a11000, 58140) = 0
set_tid_address(0x7f25a27386d0) = 1376
set_robust_list(0x7f25a27386e0, 24) = 0
rt_sigaction(SIGRTMIN, {sa_handler=0x7f25a273fbf0, sa_mask=[], sa_flags=SA_RESTORER|SA_SIGINFO, sa_restorer=0x7f25a274d3c0}, NULL, 8) = 0
rt_sigaction(SIGRT_1, {sa_handler=0x7f25a273fc90, sa_mask=[], sa_flags=SA_RESTORER|SA_RESTART|SA_SIGINFO, sa_restorer=0x7f25a274d3c0}, NULL, 8) = 0
rt_sigprocmask(SIG_UNBLOCK, [RTMIN RT_1], NULL, 8) = 0
prlimit64(0, RLIMIT_STACK, NULL, {rlim_cur=8192*1024, rlim_max=RLIM64_INFINITY}) = 0
statfs("/sys/fs/selinux", 0x7ffc4fdc8f90) = -1 ENOENT (No such file or directory)
statfs("/selinux", 0x7ffc4fdc8f90) = -1 ENOENT (No such file or directory)
brk(NULL) = 0x5616fe4fa000
brk(0x5616fe51b000) = 0x5616fe51b000
openat(AT_FDCWD, "/proc/filesystems", O_RDONLY|O_CLOEXEC) = 3
fstat(3, {st_mode=S_IFREG|0444, st_size=0, ...}) = 0
read(3, "nodev\tsysfs\nnodev\ttmpfs\nnodev\tbd"..., 1024) = 360
read(3, "", 1024) = 0 close(3) = 0
access("/etc/selinux/config", F_OK) = -1 ENOENT (No such file or directory)
openat(AT_FDCWD, "/usr/lib/locale/locale-archive", O_RDONLY|O_CLOEXEC) = 3
fstat(3, {st_mode=S_IFREG|0644, st_size=5699248, ...}) = 0
mmap(NULL, 5699248, PROT_READ, MAP_PRIVATE, 3, 0) = 0x7f25a21c7000
close(3) = 0
ioctl(1, TCGETS, {B38400 opost isig icanon echo ...}) = 0
ioctl(1, TIOCGWINSZ, {ws_row=24, ws_col=80, ws_xpixel=0, ws_ypixel=0}) = 0
openat(AT_FDCWD, ".", O_RDONLY|O_NONBLOCK|O_CLOEXEC|O_DIRECTORY) = 3
fstat(3, {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0
getdents64(3, /* 20 entries */, 32768) = 624 getdents64(3, /* 0 entries */, 32768) = 0
close(3) = 0
fstat(1, {st_mode=S_IFCHR|0620, st_rdev=makedev(0x88, 0), ...}) = 0
write(1, "Desktop Documents Downloads M"..., 72Desktop Documents Downloads Music Pictures Public Templates Videos ) = 72
close(1) = 0 close(2) = 0
exit_group(0) = ? +++ exited with 0 +++
in simple beginner terms, what are shared libraries
共享库允许
- 二进制文件共享通用代码,因此您不会在磁盘和 RAM 中存储 1000 多个单独的
printf
代码实例,并且 - 允许错误修复同时影响所有二进制文件。
(1) 在磁盘为 10MiB 而 64KiB 是 lot RAM 时曾经很重要,但现在这个原因的重要性已经降低。
(2) 的重要性已显着增加——在单个系统上有 1000 多个二进制文件,将它们全部重建是不切实际的(如果不是共享库,这将是 bug 修复生效所必需的)。
and why does ls need so many
它只使用了几个库:libc.so.6
、libdl.so.2
和libpthread.so.0
、libselinux.so.1
和libpcre2-8.so.0
.为了比较,firefox
或 google-chrome
使用 90+,而我使用的一些二进制文件使用 10,000+。
ls
不一定是一个简单的程序 -- 它可以做颜色,它可以在多个语言环境中显示和排序文件名等。