Linux: 性能: sysctl vs echo vs直接使用fopen

简介

在实际的生产中,需要对系统参数做修改,有三种方式可以实现,一个是sysctl命令来修改,一个是使用echo 命令来写入,另一个是使用fopen/write接口函数来操作配置文件。
这个对比也是相当的明显,echo要比sysctl的轻便些;因为sysctl的依赖库更多,需要加载的so也就多。相对于echo,直接操作文件的方式更优。

ldd对比

<sec01-oam-a:root>/root:
# ldd /usr/sbin/sysctllinux-vdso.so.1 (0x00007ffc63dc7000)libprocps.so.7 => /lib64/libprocps.so.7 (0x00007f9e62fa2000)libsystemd.so.0 => /lib64/libsystemd.so.0 (0x00007f9e62c56000)libdl.so.2 => /lib64/libdl.so.2 (0x00007f9e62a52000)libc.so.6 => /lib64/libc.so.6 (0x00007f9e6268d000)librt.so.1 => /lib64/librt.so.1 (0x00007f9e62485000)liblzma.so.5 => /lib64/liblzma.so.5 (0x00007f9e6225e000)liblz4.so.1 => /lib64/liblz4.so.1 (0x00007f9e62041000)libcap.so.2 => /lib64/libcap.so.2 (0x00007f9e61e39000)libmount.so.1 => /lib64/libmount.so.1 (0x00007f9e61bdf000)libgcrypt.so.20 => /lib64/libgcrypt.so.20 (0x00007f9e618c1000)libgcc_s.so.1 => /lib64/libgcc_s.so.1 (0x00007f9e616a9000)libpthread.so.0 => /lib64/libpthread.so.0 (0x00007f9e61489000)/lib64/ld-linux-x86-64.so.2 (0x00007f9e633d0000)libblkid.so.1 => /lib64/libblkid.so.1 (0x00007f9e61236000)libuuid.so.1 => /lib64/libuuid.so.1 (0x00007f9e6102e000)libselinux.so.1 => /lib64/libselinux.so.1 (0x00007f9e60e03000)libgpg-error.so.0 => /lib64/libgpg-error.so.0 (0x00007f9e60be2000)libpcre2-8.so.0 => /lib64/libpcre2-8.so.0 (0x00007f9e6095e000)
<sec01-oam-a:root>/root:
# which echo
/usr/bin/echo
<sec01-oam-a:root>/root:
# ldd /usr/bin/echolinux-vdso.so.1 (0x00007ffccf9f0000)libc.so.6 => /lib64/libc.so.6 (0x00007f5d8b4c2000)/lib64/ld-linux-x86-64.so.2 (0x00007f5d8ba90000)

下面是sysctl的strace;

# /root/strace sysctl -w net.ipv4.conf.oam2.forwarding=1
execve("/usr/sbin/sysctl", ["sysctl", "-w", "net.ipv4.conf.oam2.forwarding=1"], 0x7ffc55a74680 /* 27 vars */) = 0
brk(NULL)                               = 0x55c5a9d04000
arch_prctl(0x3001 /* ARCH_??? */, 0x7fff46315090) = -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=24207, ...}) = 0
mmap(NULL, 24207, PROT_READ, MAP_PRIVATE, 3, 0) = 0x7f2f1f2ca000
close(3)                                = 0
openat(AT_FDCWD, "/lib64/libprocps.so.7", O_RDONLY|O_CLOEXEC) = 3
read(3, "\177ELF\2\1\1\0\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0\0M\0\0\0\0\0\0"..., 832) = 832
lseek(3, 69224, SEEK_SET)               = 69224
read(3, "\4\0\0\0\20\0\0\0\5\0\0\0GNU\0\2\0\0\300\4\0\0\0\3\0\0\0\0\0\0\0", 32) = 32
fstat(3, {st_mode=S_IFREG|0755, st_size=83312, ...}) = 0
mmap(NULL, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f2f1f2c8000
lseek(3, 69224, SEEK_SET)               = 69224
read(3, "\4\0\0\0\20\0\0\0\5\0\0\0GNU\0\2\0\0\300\4\0\0\0\3\0\0\0\0\0\0\0", 32) = 32
mmap(NULL, 2252824, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x7f2f1ee7b000
mprotect(0x7f2f1ee8c000, 2097152, PROT_NONE) = 0
mmap(0x7f2f1f08c000, 12288, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x11000) = 0x7f2f1f08c000
mmap(0x7f2f1f08f000, 73752, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0x7f2f1f08f000
close(3)                                = 0
openat(AT_FDCWD, "/lib64/libsystemd.so.0", O_RDONLY|O_CLOEXEC) = 3
read(3, "\177ELF\2\1\1\0\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0p\235\1\0\0\0\0\0"..., 832) = 832
lseek(3, 1319560, SEEK_SET)             = 1319560
read(3, "\4\0\0\0\20\0\0\0\5\0\0\0GNU\0\2\0\0\300\4\0\0\0\3\0\0\0\0\0\0\0", 32) = 32
fstat(3, {st_mode=S_IFREG|0755, st_size=1387696, ...}) = 0
lseek(3, 1319560, SEEK_SET)             = 1319560
read(3, "\4\0\0\0\20\0\0\0\5\0\0\0GNU\0\2\0\0\300\4\0\0\0\3\0\0\0\0\0\0\0", 32) = 32
mmap(NULL, 3453880, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x7f2f1eb2f000
mprotect(0x7f2f1ec72000, 2093056, PROT_NONE) = 0
mmap(0x7f2f1ee71000, 36864, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x142000) = 0x7f2f1ee71000
mmap(0x7f2f1ee7a000, 952, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0x7f2f1ee7a000
close(3)                                = 0
openat(AT_FDCWD, "/lib64/libdl.so.2", O_RDONLY|O_CLOEXEC) = 3
read(3, "\177ELF\2\1\1\0\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0p\16\0\0\0\0\0\0"..., 832) = 832
fstat(3, {st_mode=S_IFREG|0755, st_size=19128, ...}) = 0
mmap(NULL, 2109600, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x7f2f1e92b000
mprotect(0x7f2f1e92e000, 2093056, PROT_NONE) = 0
mmap(0x7f2f1eb2d000, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x2000) = 0x7f2f1eb2d000
close(3)                                = 0
openat(AT_FDCWD, "/lib64/libc.so.6", O_RDONLY|O_CLOEXEC) = 3
read(3, "\177ELF\2\1\1\3\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0`\256\3\0\0\0\0\0"..., 832) = 832
fstat(3, {st_mode=S_IFREG|0755, st_size=2089936, ...}) = 0
lseek(3, 808, SEEK_SET)                 = 808
read(3, "\4\0\0\0\20\0\0\0\5\0\0\0GNU\0\2\0\0\300\4\0\0\0\3\0\0\0\0\0\0\0", 32) = 32
mmap(NULL, 3950816, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x7f2f1e566000
mprotect(0x7f2f1e722000, 2093056, PROT_NONE) = 0
mmap(0x7f2f1e921000, 24576, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x1bb000) = 0x7f2f1e921000
mmap(0x7f2f1e927000, 14560, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0x7f2f1e927000
close(3)                                = 0
openat(AT_FDCWD, "/lib64/librt.so.1", O_RDONLY|O_CLOEXEC) = 3
read(3, "\177ELF\2\1\1\0\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0000$\0\0\0\0\0\0"..., 832) = 832
fstat(3, {st_mode=S_IFREG|0755, st_size=42744, ...}) = 0
mmap(NULL, 2128832, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x7f2f1e35e000
mprotect(0x7f2f1e365000, 2093056, PROT_NONE) = 0
mmap(0x7f2f1e564000, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x6000) = 0x7f2f1e564000
close(3)                                = 0
openat(AT_FDCWD, "/lib64/liblzma.so.5", O_RDONLY|O_CLOEXEC) = 3
read(3, "\177ELF\2\1\1\0\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0\3205\0\0\0\0\0\0"..., 832) = 832
lseek(3, 151120, SEEK_SET)              = 151120
read(3, "\4\0\0\0\20\0\0\0\5\0\0\0GNU\0\2\0\0\300\4\0\0\0\3\0\0\0\0\0\0\0", 32) = 32
fstat(3, {st_mode=S_IFREG|0755, st_size=162192, ...}) = 0
lseek(3, 151120, SEEK_SET)              = 151120
read(3, "\4\0\0\0\20\0\0\0\5\0\0\0GNU\0\2\0\0\300\4\0\0\0\3\0\0\0\0\0\0\0", 32) = 32
mmap(NULL, 2252808, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x7f2f1e137000
mprotect(0x7f2f1e15c000, 2097152, PROT_NONE) = 0
mmap(0x7f2f1e35c000, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x25000) = 0x7f2f1e35c000
mmap(0x7f2f1e35d000, 8, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0x7f2f1e35d000
close(3)                                = 0
openat(AT_FDCWD, "/lib64/liblz4.so.1", O_RDONLY|O_CLOEXEC) = 3
read(3, "\177ELF\2\1\1\0\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0@$\0\0\0\0\0\0"..., 832) = 832
lseek(3, 112464, SEEK_SET)              = 112464
read(3, "\4\0\0\0\20\0\0\0\5\0\0\0GNU\0\2\0\0\300\4\0\0\0\3\0\0\0\0\0\0\0", 32) = 32
fstat(3, {st_mode=S_IFREG|0755, st_size=119760, ...}) = 0
mmap(NULL, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f2f1f2c6000
lseek(3, 112464, SEEK_SET)              = 112464
read(3, "\4\0\0\0\20\0\0\0\5\0\0\0GNU\0\2\0\0\300\4\0\0\0\3\0\0\0\0\0\0\0", 32) = 32
mmap(NULL, 2211848, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x7f2f1df1a000
mprotect(0x7f2f1df36000, 2093056, PROT_NONE) = 0
mmap(0x7f2f1e135000, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x1b000) = 0x7f2f1e135000
mmap(0x7f2f1e136000, 8, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0x7f2f1e136000
close(3)                                = 0
openat(AT_FDCWD, "/lib64/libcap.so.2", O_RDONLY|O_CLOEXEC) = 3
read(3, "\177ELF\2\1\1\0\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0\220&\0\0\0\0\0\0"..., 832) = 832
lseek(3, 26952, SEEK_SET)               = 26952
read(3, "\4\0\0\0\20\0\0\0\5\0\0\0GNU\0\2\0\0\300\4\0\0\0\3\0\0\0\0\0\0\0", 32) = 32
fstat(3, {st_mode=S_IFREG|0755, st_size=33752, ...}) = 0
lseek(3, 26952, SEEK_SET)               = 26952
read(3, "\4\0\0\0\20\0\0\0\5\0\0\0GNU\0\2\0\0\300\4\0\0\0\3\0\0\0\0\0\0\0", 32) = 32
mmap(NULL, 2126224, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x7f2f1dd12000
mprotect(0x7f2f1dd19000, 2093056, PROT_NONE) = 0
mmap(0x7f2f1df18000, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x6000) = 0x7f2f1df18000
close(3)                                = 0
openat(AT_FDCWD, "/lib64/libmount.so.1", O_RDONLY|O_CLOEXEC) = 3
read(3, "\177ELF\2\1\1\0\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0\260\352\0\0\0\0\0\0"..., 832) = 832
lseek(3, 348744, SEEK_SET)              = 348744
read(3, "\4\0\0\0\20\0\0\0\5\0\0\0GNU\0\2\0\0\300\4\0\0\0\3\0\0\0\0\0\0\0", 32) = 32
fstat(3, {st_mode=S_IFREG|0755, st_size=371384, ...}) = 0
lseek(3, 348744, SEEK_SET)              = 348744
read(3, "\4\0\0\0\20\0\0\0\5\0\0\0GNU\0\2\0\0\300\4\0\0\0\3\0\0\0\0\0\0\0", 32) = 32
mmap(NULL, 2462976, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x7f2f1dab8000
mprotect(0x7f2f1db0e000, 2093056, PROT_NONE) = 0
mmap(0x7f2f1dd0d000, 16384, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x55000) = 0x7f2f1dd0d000
mmap(0x7f2f1dd11000, 1280, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0x7f2f1dd11000
close(3)                                = 0
openat(AT_FDCWD, "/lib64/libgcrypt.so.20", O_RDONLY|O_CLOEXEC) = 3
read(3, "\177ELF\2\1\1\0\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0\0\273\0\0\0\0\0\0"..., 832) = 832
lseek(3, 1143920, SEEK_SET)             = 1143920
read(3, "\4\0\0\0\20\0\0\0\5\0\0\0GNU\0\2\0\0\300\4\0\0\0\3\0\0\0\0\0\0\0", 32) = 32
fstat(3, {st_mode=S_IFREG|0755, st_size=1187328, ...}) = 0
lseek(3, 1143920, SEEK_SET)             = 1143920
read(3, "\4\0\0\0\20\0\0\0\5\0\0\0GNU\0\2\0\0\300\4\0\0\0\3\0\0\0\0\0\0\0", 32) = 32
mmap(NULL, 3268552, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x7f2f1d79a000
mprotect(0x7f2f1d8b2000, 2093056, PROT_NONE) = 0
mmap(0x7f2f1dab1000, 28672, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x117000) = 0x7f2f1dab1000
close(3)                                = 0
openat(AT_FDCWD, "/lib64/libgcc_s.so.1", O_RDONLY|O_CLOEXEC) = 3
read(3, "\177ELF\2\1\1\0\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0\0.\0\0\0\0\0\0"..., 832) = 832
lseek(3, 92624, SEEK_SET)               = 92624
read(3, "\4\0\0\0\20\0\0\0\5\0\0\0GNU\0\2\0\0\300\4\0\0\0\3\0\0\0\0\0\0\0", 32) = 32
fstat(3, {st_mode=S_IFREG|0755, st_size=99664, ...}) = 0
lseek(3, 92624, SEEK_SET)               = 92624
read(3, "\4\0\0\0\20\0\0\0\5\0\0\0GNU\0\2\0\0\300\4\0\0\0\3\0\0\0\0\0\0\0", 32) = 32
mmap(NULL, 2192080, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x7f2f1d582000
mprotect(0x7f2f1d599000, 2093056, PROT_NONE) = 0
mmap(0x7f2f1d798000, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x16000) = 0x7f2f1d798000
close(3)                                = 0
openat(AT_FDCWD, "/lib64/libpthread.so.0", O_RDONLY|O_CLOEXEC) = 3
read(3, "\177ELF\2\1\1\0\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0\360n\0\0\0\0\0\0"..., 832) = 832
fstat(3, {st_mode=S_IFREG|0755, st_size=149976, ...}) = 0
mmap(NULL, 2225344, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x7f2f1d362000
mprotect(0x7f2f1d37d000, 2093056, PROT_NONE) = 0
mmap(0x7f2f1d57c000, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x1a000) = 0x7f2f1d57c000
mmap(0x7f2f1d57e000, 13504, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0x7f2f1d57e000
close(3)                                = 0
openat(AT_FDCWD, "/lib64/libblkid.so.1", O_RDONLY|O_CLOEXEC) = 3
read(3, "\177ELF\2\1\1\0\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0@\267\0\0\0\0\0\0"..., 832) = 832
lseek(3, 311944, SEEK_SET)              = 311944
read(3, "\4\0\0\0\20\0\0\0\5\0\0\0GNU\0\2\0\0\300\4\0\0\0\3\0\0\0\0\0\0\0", 32) = 32
fstat(3, {st_mode=S_IFREG|0755, st_size=343624, ...}) = 0
mmap(NULL, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f2f1f2c4000
lseek(3, 311944, SEEK_SET)              = 311944
read(3, "\4\0\0\0\20\0\0\0\5\0\0\0GNU\0\2\0\0\300\4\0\0\0\3\0\0\0\0\0\0\0", 32) = 32
mmap(NULL, 2434848, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x7f2f1d10f000
mprotect(0x7f2f1d15c000, 2093056, PROT_NONE) = 0
mmap(0x7f2f1d35b000, 24576, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x4c000) = 0x7f2f1d35b000
mmap(0x7f2f1d361000, 1824, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0x7f2f1d361000
close(3)                                = 0
openat(AT_FDCWD, "/lib64/libuuid.so.1", O_RDONLY|O_CLOEXEC) = 3
read(3, "\177ELF\2\1\1\0\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0\300\32\0\0\0\0\0\0"..., 832) = 832
lseek(3, 25296, SEEK_SET)               = 25296
read(3, "\4\0\0\0\20\0\0\0\5\0\0\0GNU\0\2\0\0\300\4\0\0\0\3\0\0\0\0\0\0\0", 32) = 32
fstat(3, {st_mode=S_IFREG|0755, st_size=33480, ...}) = 0
lseek(3, 25296, SEEK_SET)               = 25296
read(3, "\4\0\0\0\20\0\0\0\5\0\0\0GNU\0\2\0\0\300\4\0\0\0\3\0\0\0\0\0\0\0", 32) = 32
mmap(NULL, 2125856, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x7f2f1cf07000
mprotect(0x7f2f1cf0e000, 2093056, PROT_NONE) = 0
mmap(0x7f2f1d10d000, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x6000) = 0x7f2f1d10d000
mmap(0x7f2f1d10e000, 32, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0x7f2f1d10e000
close(3)                                = 0
openat(AT_FDCWD, "/lib64/libselinux.so.1", O_RDONLY|O_CLOEXEC) = 3
read(3, "\177ELF\2\1\1\0\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0\200z\0\0\0\0\0\0"..., 832) = 832
lseek(3, 157360, SEEK_SET)              = 157360
read(3, "\4\0\0\0\20\0\0\0\5\0\0\0GNU\0\2\0\0\300\4\0\0\0\3\0\0\0\0\0\0\0", 32) = 32
fstat(3, {st_mode=S_IFREG|0755, st_size=172104, ...}) = 0
lseek(3, 157360, SEEK_SET)              = 157360
read(3, "\4\0\0\0\20\0\0\0\5\0\0\0GNU\0\2\0\0\300\4\0\0\0\3\0\0\0\0\0\0\0", 32) = 32
mmap(NULL, 2270704, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x7f2f1ccdc000
mprotect(0x7f2f1cd03000, 2097152, PROT_NONE) = 0
mmap(0x7f2f1cf03000, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x27000) = 0x7f2f1cf03000
mmap(0x7f2f1cf05000, 5616, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0x7f2f1cf05000
close(3)                                = 0
openat(AT_FDCWD, "/lib64/libgpg-error.so.0", O_RDONLY|O_CLOEXEC) = 3
read(3, "\177ELF\2\1\1\0\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0PH\0\0\0\0\0\0"..., 832) = 832
lseek(3, 125832, SEEK_SET)              = 125832
read(3, "\4\0\0\0\20\0\0\0\5\0\0\0GNU\0\2\0\0\300\4\0\0\0\3\0\0\0\0\0\0\0", 32) = 32
fstat(3, {st_mode=S_IFREG|0755, st_size=144392, ...}) = 0
lseek(3, 125832, SEEK_SET)              = 125832
read(3, "\4\0\0\0\20\0\0\0\5\0\0\0GNU\0\2\0\0\300\4\0\0\0\3\0\0\0\0\0\0\0", 32) = 32
mmap(NULL, 2228800, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x7f2f1cabb000
mprotect(0x7f2f1cada000, 2097152, PROT_NONE) = 0
mmap(0x7f2f1ccda000, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x1f000) = 0x7f2f1ccda000
close(3)                                = 0
openat(AT_FDCWD, "/lib64/libpcre2-8.so.0", O_RDONLY|O_CLOEXEC) = 3
read(3, "\177ELF\2\1\1\0\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0\200#\0\0\0\0\0\0"..., 832) = 832
lseek(3, 533040, SEEK_SET)              = 533040
read(3, "\4\0\0\0\20\0\0\0\5\0\0\0GNU\0\2\0\0\300\4\0\0\0\3\0\0\0\0\0\0\0", 32) = 32
fstat(3, {st_mode=S_IFREG|0755, st_size=543304, ...}) = 0
lseek(3, 533040, SEEK_SET)              = 533040
read(3, "\4\0\0\0\20\0\0\0\5\0\0\0GNU\0\2\0\0\300\4\0\0\0\3\0\0\0\0\0\0\0", 32) = 32
mmap(NULL, 2634280, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x7f2f1c837000
mprotect(0x7f2f1c8ba000, 2093056, PROT_NONE) = 0
mmap(0x7f2f1cab9000, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x82000) = 0x7f2f1cab9000
close(3)                                = 0
mmap(NULL, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f2f1f2c2000
mmap(NULL, 12288, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f2f1f2bf000
arch_prctl(ARCH_SET_FS, 0x7f2f1f2bf940) = 0
mprotect(0x7f2f1e921000, 16384, PROT_READ) = 0
mprotect(0x7f2f1d57c000, 4096, PROT_READ) = 0
mprotect(0x7f2f1cab9000, 4096, PROT_READ) = 0
mprotect(0x7f2f1ccda000, 4096, PROT_READ) = 0
mprotect(0x7f2f1eb2d000, 4096, PROT_READ) = 0
mprotect(0x7f2f1cf03000, 4096, PROT_READ) = 0
mprotect(0x7f2f1d10d000, 4096, PROT_READ) = 0
mprotect(0x7f2f1d35b000, 20480, PROT_READ) = 0
mprotect(0x7f2f1d798000, 4096, PROT_READ) = 0
mprotect(0x7f2f1dab1000, 8192, PROT_READ) = 0
mprotect(0x7f2f1e564000, 4096, PROT_READ) = 0
mprotect(0x7f2f1dd0d000, 12288, PROT_READ) = 0
mprotect(0x7f2f1df18000, 4096, PROT_READ) = 0
mprotect(0x7f2f1e135000, 4096, PROT_READ) = 0
mprotect(0x7f2f1e35c000, 4096, PROT_READ) = 0
mprotect(0x7f2f1ee71000, 32768, PROT_READ) = 0
mprotect(0x7f2f1f08c000, 8192, PROT_READ) = 0
mprotect(0x55c5a8c7c000, 4096, PROT_READ) = 0
mprotect(0x7f2f1f2d0000, 4096, PROT_READ) = 0
munmap(0x7f2f1f2ca000, 24207)           = 0
set_tid_address(0x7f2f1f2bfc10)         = 1005130
set_robust_list(0x7f2f1f2bfc20, 24)     = 0
rt_sigaction(SIGRTMIN, {sa_handler=0x7f2f1d368970, sa_mask=[], sa_flags=SA_RESTORER|SA_SIGINFO, sa_restorer=0x7f2f1d374cf0}, NULL, 8) = 0
rt_sigaction(SIGRT_1, {sa_handler=0x7f2f1d368a00, sa_mask=[], sa_flags=SA_RESTORER|SA_RESTART|SA_SIGINFO, sa_restorer=0x7f2f1d374cf0}, 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
getrandom("\x02\x56\x3e\xec\x56\xaa\x40\x97", 8, GRND_NONBLOCK) = 8
brk(NULL)                               = 0x55c5a9d04000
brk(0x55c5a9d25000)                     = 0x55c5a9d25000
statfs("/sys/fs/selinux", {f_type=SELINUX_MAGIC, f_bsize=4096, f_blocks=0, f_bfree=0, f_bavail=0, f_files=0, f_ffree=0, f_fsid={val=[0, 0]}, f_namelen=255, f_frsize=4096, f_flags=ST_VALID|ST_RELATIME}) = 0
statfs("/sys/fs/selinux", {f_type=SELINUX_MAGIC, f_bsize=4096, f_blocks=0, f_bfree=0, f_bavail=0, f_files=0, f_ffree=0, f_fsid={val=[0, 0]}, f_namelen=255, f_frsize=4096, f_flags=ST_VALID|ST_RELATIME}) = 0
access("/etc/selinux/config", F_OK)     = -1 ENOENT (No such file or directory)
access("/etc/system-fips", F_OK)        = -1 ENOENT (No such file or directory)
access("/etc/gcrypt/fips_enabled", F_OK) = -1 ENOENT (No such file or directory)
openat(AT_FDCWD, "/proc/sys/crypto/fips_enabled", O_RDONLY) = 3
fstat(3, {st_mode=S_IFREG|0444, st_size=0, ...}) = 0
read(3, "0\n", 1024)                    = 2
close(3)                                = 0
prctl(PR_CAPBSET_READ, CAP_MAC_OVERRIDE) = 1
prctl(PR_CAPBSET_READ, 0x30 /* CAP_??? */) = -1 EINVAL (Invalid argument)
prctl(PR_CAPBSET_READ, 0x28 /* CAP_??? */) = 1
prctl(PR_CAPBSET_READ, 0x2c /* CAP_??? */) = -1 EINVAL (Invalid argument)
prctl(PR_CAPBSET_READ, 0x2a /* CAP_??? */) = -1 EINVAL (Invalid argument)
prctl(PR_CAPBSET_READ, 0x29 /* CAP_??? */) = -1 EINVAL (Invalid argument)
openat(AT_FDCWD, "/proc/self/auxv", O_RDONLY) = 3
fstat(3, {st_mode=S_IFREG|0400, st_size=0, ...}) = 0
read(3, "!\0\0\0\0\0\0\0\0\2603F\377\177\0\0003\0\0\0\0\0\0\0\360\6\0\0\0\0\0\0"..., 1024) = 336
close(3)                                = 0
openat(AT_FDCWD, "/proc/sys/kernel/osrelease", O_RDONLY) = 3
fstat(3, {st_mode=S_IFREG|0444, st_size=0, ...}) = 0
read(3, "4.18.0-513.11.1.el8_9.x86_64\n", 1024) = 29
close(3)                                = 0
openat(AT_FDCWD, "/sys/devices/system/cpu/online", O_RDONLY|O_CLOEXEC) = 3
read(3, "0-1\n", 8192)                  = 4
close(3)                                = 0
openat(AT_FDCWD, "/proc/self/auxv", O_RDONLY) = 3
fstat(3, {st_mode=S_IFREG|0400, st_size=0, ...}) = 0
read(3, "!\0\0\0\0\0\0\0\0\2603F\377\177\0\0003\0\0\0\0\0\0\0\360\6\0\0\0\0\0\0"..., 1024) = 336
close(3)                                = 0
stat("/proc/sys/net/ipv4/conf/oam2/forwarding", {st_mode=S_IFREG|0644, st_size=0, ...}) = 0
openat(AT_FDCWD, "/proc/sys/net/ipv4/conf/oam2/forwarding", O_WRONLY|O_TRUNC) = 3
write(3, "1\n", 2)                      = 2
close(3)                                = 0
fstat(1, {st_mode=S_IFCHR|0620, st_rdev=makedev(0x88, 0x2), ...}) = 0
write(1, "net.ipv4.conf.oam2.forwarding = "..., 34net.ipv4.conf.oam2.forwarding = 1
) = 34
close(1)                                = 0
close(2)                                = 0
exit_group(0)                           = ?
+++ exited with 0 +++

下面是echo的strace

<sec01-oam-a:root>/proc/sys/net/ipv4/conf/oam2:
# /root/strace echo 1 > forwarding
execve("/usr/bin/echo", ["echo", "1"], 0x7fff4224fe48 /* 27 vars */) = 0
brk(NULL)                               = 0x55c8e50b8000
arch_prctl(0x3001 /* ARCH_??? */, 0x7ffd56e37120) = -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=24207, ...}) = 0
mmap(NULL, 24207, PROT_READ, MAP_PRIVATE, 3, 0) = 0x7f372727d000
close(3)                                = 0
openat(AT_FDCWD, "/lib64/libc.so.6", O_RDONLY|O_CLOEXEC) = 3
read(3, "\177ELF\2\1\1\3\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0`\256\3\0\0\0\0\0"..., 832) = 832
fstat(3, {st_mode=S_IFREG|0755, st_size=2089936, ...}) = 0
mmap(NULL, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f372727b000
lseek(3, 808, SEEK_SET)                 = 808
read(3, "\4\0\0\0\20\0\0\0\5\0\0\0GNU\0\2\0\0\300\4\0\0\0\3\0\0\0\0\0\0\0", 32) = 32
mmap(NULL, 3950816, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x7f3726c90000
mprotect(0x7f3726e4c000, 2093056, PROT_NONE) = 0
mmap(0x7f372704b000, 24576, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x1bb000) = 0x7f372704b000
mmap(0x7f3727051000, 14560, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0x7f3727051000
close(3)                                = 0
arch_prctl(ARCH_SET_FS, 0x7f372727c540) = 0
mprotect(0x7f372704b000, 16384, PROT_READ) = 0
mprotect(0x55c8e3bd3000, 4096, PROT_READ) = 0
mprotect(0x7f3727283000, 4096, PROT_READ) = 0
munmap(0x7f372727d000, 24207)           = 0
getrandom("\x57\x18\x64\x5a\x85\x50\x8b\xf1", 8, GRND_NONBLOCK) = 8
brk(NULL)                               = 0x55c8e50b8000
brk(0x55c8e50d9000)                     = 0x55c8e50d9000
brk(NULL)                               = 0x55c8e50d9000
fstat(1, {st_mode=S_IFREG|0644, st_size=0, ...}) = 0
write(1, "1\n", 2)                      = 2
close(1)                                = 0
close(2)                                = 0
exit_group(0)                           = ?
+++ exited with 0 +++

直接使用fopen/write接口函数

实现配置文件的修改,这个方法在应用程序,非脚本语言里,速度更快。可以尝试。

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/824777.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

54岁前港姐与好友因一事反目成仇,20年后方破冰

现年54岁的前「金牌司仪」陈淽菁&#xff08;前名&#xff1a;陈芷菁&#xff09;是1994年落选港姐&#xff0c;之后加入TVB参演电视剧《天地男儿》、《壹号皇庭》入屋&#xff0c;后因口齿伶俐而转战主持界。2017年陈淽菁离巢&#xff0c;外出以个人名义成立「陈芷菁工作室」&…

每日学习笔记:C++ STL算法之容器元素转换、结合、互换

本文API 转换元素 transform(sourceBeg,sourceEnd,destBeg, op) 结合元素 transform(source1Beg,source1End,source2Beg,destBeg, op) 互换元素 swap_ranges(sourceBeg,sourceEnd,destBeg) 转换元素 结合元素 互换元素

聚焦ChatGPT:让论文写作更高效更精准

ChatGPT无限次数:点击直达 html 聚焦ChatGPT&#xff1a;让论文写作更高效更精准 引言 在当今信息爆炸的时代&#xff0c;撰写高质量论文变得越发重要。然而&#xff0c;许多研究者和学者在论文写作过程中常常遇到困难&#xff0c;例如构思内容、整合观点和确保表达准确。…

什么是Cookies?请求Cookies和响应 Cookies的关系

一、什么是cookies 在早期的网络发展中&#xff0c;如何管理状态一直是一个棘手的问题。由于HTTP协议的无状态特性&#xff0c;服务器无法判断连续的两个请求是否来自同一个浏览器。为了解决这个问题&#xff0c;最初的方案是在请求时将一些参数嵌入到页面中&#xff0c;并在…

深度学习驱动的流体力学计算与应用

在深度学习与流体力学深度融合的背景下&#xff0c;科研边界不断拓展&#xff0c;创新成果层出不穷。从物理模型融合到复杂流动模拟&#xff0c;从数据驱动研究到流场智能分析&#xff0c;深度学习正以前所未有的力量重塑流体力学领域。近期在Nature和Science杂志上发表的深度学…

ARM_day8:温湿度数据采集应用

1、IIC通信过程 主机发送起始信号、主机发送8位(7位从机地址1位传送方向(0W&#xff0c;1R))、从机应答、发数据、应答、数据传输完&#xff0c;主机发送停止信号 2、起始信号和终止信号 SCL时钟线&#xff0c;SDA数据线 SCL高电平&#xff0c;SDA由高到低——起始信号 SC…

继承的初步

完成两个类&#xff0c;一个类Animal&#xff0c;表示动物类&#xff0c;有一个成员表示年龄。一个类Dog&#xff0c;继承自Animal&#xff0c;有一个新的数据成员表示颜色&#xff0c;合理设计这两个类&#xff0c;使得测试程序可以运行并得到正确的结果。 函数接口定义&…

我为什么选择做程序员

我选择做程序员的原因有多个方面。首先&#xff0c;我对计算机科学和技术有着浓厚的兴趣。从小我就对计算机的工作原理和软件开发充满好奇&#xff0c;喜欢探索新技术和解决问题。这种兴趣促使我深入学习和研究计算机领域的知识&#xff0c;最终选择了程序员这一职业。 其次&a…

php正则表达式压缩与格式化html,css,js

注意事项 只支持压缩含一个<script></script>的html,且变量内多个空格也会被压缩为一个 格式化html单标签需要添加/结束 压缩html 去除<!-- -->内的全部内容 多个空白符变为一个空格 去除> <内的空白符 压缩css 去除/* */内的全部内容 多个空白符变为一…

汽车零部件制造迎来智能化升级,3D视觉定位系统助力无人化生产线建设

随着新能源汽车市场的蓬勃发展&#xff0c;汽车零部件制造行业正面临着前所未有的机遇与挑战。为了提高产能和产品加工精度&#xff0c;某专业铝合金汽车零部件制造商决定引进智能生产线&#xff0c;其中&#xff0c;对成垛摆放的变速箱壳体进行机床上料成为关键一环。 传统的上…

小程序如何引入自定义组件

要在小程序中引入自定义组件&#xff0c;你可以按照以下步骤进行操作&#xff1a; 1. 创建自定义组件&#xff1a;首先在小程序项目中创建一个自定义组件。在项目目录下的components文件夹中创建一个新的文件夹&#xff0c;用于存放自定义组件相关的文件。通常&#xff0c;一个…

CESSCN认证通信网络安全服务能力评定企业资质介绍

通信网络安全服务能力评定资质是中国通信企业协会通信网络安全专业委员会&#xff08;简称通信安委会&#xff09;颁发的一项专业资质&#xff0c;旨在评定通信网络安全服务单位的服务资格、水平和能力。这项资质对于从事网络安全服务的企业尤为重要&#xff0c;因为它直接反映…

SpringBootSpringCloud升级可能会出现的问题

1.背景 之前负责过我们中台的SpringBoot和Cloud的升级&#xff0c;特次记录分享一下项目中可能出现的问题&#xff0c;方便后续的人快速定位问题。以及下述选择的解决方案都是基于让升级的服务影响和改动最小以及提供通用的解决方案的提前进行选择的。 1.1版本说明 升级前&a…

陇剑杯 省赛 攻击者1 CTF wireshark 流量分析

陇剑杯 省赛 攻击者1 题目 链接&#xff1a;https://pan.baidu.com/s/1KSSXOVNPC5hu_Mf60uKM2A?pwdhaek 提取码&#xff1a;haek ├───LogAnalize │ ├───linux简单日志分析 │ │ linux-log_2.zip │ │ │ ├───misc日志分析 │ │ acce…

Vue3项目 网易严选_学习笔记

Vue3项目 网易严选_第一天 主要内容 项目搭建vuex基础路由设计首页顶部和底部布局 学习目标 知识点要求项目搭建掌握vuex基础掌握路由设计掌握首页顶部和底部布局掌握 一、项目搭建 1.1 创建项目 vue create vue-wangyi选择vue3.0版本 1.2 目录调整 大致步骤&#xff…

机器学习概论—什么是机器学习

机器学习概论—什么是机器学习 你背单词时 阿拉斯加的鳕鱼正跃出水面 你算数学时 太平洋的海鸥振翅掠过城市上空 你晚自习时 北极的夜空散漫了五彩斑斓 你熬夜加班时 地中海的茶花正破土而生 你在和朋友碰杯叙情时 飞往伦敦的最后一班航班正在跑道滑行 那些你感觉从…

Workerman开启ssl方法如下

参考地址 Workerman开启ssl方法如下-遇见你与你分享 准备工作&#xff1a; 1、Workerman版本不小于3.3.7 2、PHP安装了openssl扩展 3、已经申请了证书&#xff08;pem/crt文件及key文件&#xff09;放在了/etc/nginx/conf.d/ssl下 4、配置文件 location /wss { proxy_set…

【JavaScript】期约 Promise

ECMAScript 6 及之后的几个版本逐步加大了对异步编程机制的支持&#xff0c;提供了令人眼前一亮的新特性。ECMAScript 6 新增了正式的 Promise&#xff08;期约&#xff09;引用类型&#xff0c;支持优雅地定义和组织异步逻辑。接下来几个版本增加了使用 async 和 await 关键字…

unity制作拼接地图

前段时间有个朋友问我想要制作一款地图编辑器&#xff0c;最开始我还想着在一个平面用节点切割制作地图编辑器这倒是也行&#xff0c;但不太好控制每一个点&#xff0c;如果未来项目大了&#xff0c;更加不好维护。 偶然间翻到一篇文章&#xff1a;unity地图边缘检测 或许我们…

基于数字孪生的城市建模和仿真

近年来&#xff0c;数字孪生概念几乎呈爆炸式增长&#xff0c;利用该概念的科学文章数量呈指数级增长就证明了这一点。 这一概念源自制造业&#xff0c;使用 CAD 模型可以创建组件和产品的精确数字复制品。 该术语最早的使用可以追溯到 2003 年&#xff0c;通常归功于 Grieves …