Linux:subshell(子shell)和childprocess(子进程)

相关阅读

Linuxicon-default.png?t=N7T8https://blog.csdn.net/weixin_45791458/category_12234591.html?spm=1001.2014.3001.5482

一、预备知识

        在进行这个话题之前,首先要了解Linux系统中一个进程是如何创建的,当一个命令被执行时,首先会在当前进程创建一个子进程,这个进程除了少数地方(例如进程PID和PPID),几乎和当前进程完全一样,使用的系统调用是fork()或者clone()。

        在创建了子进程后,通常会调用exec()系列的系统函数在子进程中进行替换,从而运行一个新的程序,该程序能继承父进程中处于导出状态的变量(环境变量)和函数。且子进程中的变量赋值和其他设置不会影响父进程。

        对于后面的内容,我们把“创建子进程”当做是上面的第一步,把“创建****子进程”当做是创建进程和替换进程,即完整的两步。

        下面举例说明了上述过程,首先创建了一个shell脚本,其中只有一个sleep命令,随后使用strace命令追踪使用bash解释执行这个脚本过程中的系统调用。

# 文件test.shsleep 20
$ strace -f bash test.sh  # 需要加上-f选项,这样才能追踪子进程
execve("/usr/bin/bash", ["bash", "test.sh"], 0x7ffe5b2df940 /* 55 vars */) = 0
brk(NULL)                               = 0x55cfde987000
arch_prctl(0x3001 /* ARCH_??? */, 0x7fff3394b3b0) = -1 EINVAL (Invalid argument)
mmap(NULL, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fa2e2cac000
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
newfstatat(3, "", {st_mode=S_IFREG|0644, st_size=95179, ...}, AT_EMPTY_PATH) = 0
mmap(NULL, 95179, PROT_READ, MAP_PRIVATE, 3, 0) = 0x7fa2e2c94000
close(3)                                = 0
openat(AT_FDCWD, "/lib/x86_64-linux-gnu/libtinfo.so.6", 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\0"..., 832) = 832
newfstatat(3, "", {st_mode=S_IFREG|0644, st_size=200136, ...}, AT_EMPTY_PATH) = 0
mmap(NULL, 203040, PROT_READ, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x7fa2e2c62000
mmap(0x7fa2e2c70000, 69632, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0xe000) = 0x7fa2e2c70000
mmap(0x7fa2e2c81000, 57344, PROT_READ, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x1f000) = 0x7fa2e2c81000
mmap(0x7fa2e2c8f000, 20480, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x2c000) = 0x7fa2e2c8f000
close(3)                                = 0
openat(AT_FDCWD, "/lib/x86_64-linux-gnu/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\0P\237\2\0\0\0\0\0"..., 832) = 832
pread64(3, "\6\0\0\0\4\0\0\0@\0\0\0\0\0\0\0@\0\0\0\0\0\0\0@\0\0\0\0\0\0\0"..., 784, 64) = 784
pread64(3, "\4\0\0\0 \0\0\0\5\0\0\0GNU\0\2\0\0\300\4\0\0\0\3\0\0\0\0\0\0\0"..., 48, 848) = 48
pread64(3, "\4\0\0\0\24\0\0\0\3\0\0\0GNU\0\302\211\332Pq\2439\235\350\223\322\257\201\326\243\f"..., 68, 896) = 68
newfstatat(3, "", {st_mode=S_IFREG|0755, st_size=2220400, ...}, AT_EMPTY_PATH) = 0
pread64(3, "\6\0\0\0\4\0\0\0@\0\0\0\0\0\0\0@\0\0\0\0\0\0\0@\0\0\0\0\0\0\0"..., 784, 64) = 784
mmap(NULL, 2264656, PROT_READ, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x7fa2e2a00000
mprotect(0x7fa2e2a28000, 2023424, PROT_NONE) = 0
mmap(0x7fa2e2a28000, 1658880, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x28000) = 0x7fa2e2a28000
mmap(0x7fa2e2bbd000, 360448, PROT_READ, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x1bd000) = 0x7fa2e2bbd000
mmap(0x7fa2e2c16000, 24576, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x215000) = 0x7fa2e2c16000
mmap(0x7fa2e2c1c000, 52816, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0x7fa2e2c1c000
close(3)                                = 0
mmap(NULL, 12288, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fa2e2c5f000
arch_prctl(ARCH_SET_FS, 0x7fa2e2c5f740) = 0
set_tid_address(0x7fa2e2c5fa10)         = 4064924
set_robust_list(0x7fa2e2c5fa20, 24)     = 0
rseq(0x7fa2e2c600e0, 0x20, 0, 0x53053053) = 0
mprotect(0x7fa2e2c16000, 16384, PROT_READ) = 0
mprotect(0x7fa2e2c8f000, 16384, PROT_READ) = 0
mprotect(0x55cfdd194000, 16384, PROT_READ) = 0
mprotect(0x7fa2e2ce6000, 8192, PROT_READ) = 0
prlimit64(0, RLIMIT_STACK, NULL, {rlim_cur=8192*1024, rlim_max=RLIM64_INFINITY}) = 0
munmap(0x7fa2e2c94000, 95179)           = 0
openat(AT_FDCWD, "/dev/tty", O_RDWR|O_NONBLOCK) = 3
close(3)                                = 0
getrandom("\x34\xa4\x2c\xab\x9e\xab\xb9\x29", 8, GRND_NONBLOCK) = 8
brk(NULL)                               = 0x55cfde987000
brk(0x55cfde9a8000)                     = 0x55cfde9a8000
openat(AT_FDCWD, "/usr/lib/locale/locale-archive", O_RDONLY|O_CLOEXEC) = 3
newfstatat(3, "", {st_mode=S_IFREG|0644, st_size=8872448, ...}, AT_EMPTY_PATH) = 0
mmap(NULL, 8872448, PROT_READ, MAP_PRIVATE, 3, 0) = 0x7fa2e2000000
close(3)                                = 0
openat(AT_FDCWD, "/usr/lib/x86_64-linux-gnu/gconv/gconv-modules.cache", O_RDONLY) = 3
newfstatat(3, "", {st_mode=S_IFREG|0644, st_size=27002, ...}, AT_EMPTY_PATH) = 0
mmap(NULL, 27002, PROT_READ, MAP_SHARED, 3, 0) = 0x7fa2e2ca5000
close(3)                                = 0
futex(0x7fa2e2c1ba6c, FUTEX_WAKE_PRIVATE, 2147483647) = 0
getuid()                                = 1006
getgid()                                = 1002
geteuid()                               = 1006
getegid()                               = 1002
rt_sigprocmask(SIG_BLOCK, NULL, [], 8)  = 0
ioctl(-1, TIOCGPGRP, 0x7fff3394b2a4)    = -1 EBADF (Bad file descriptor)
sysinfo({uptime=7178153, loads=[65344, 50976, 45152], totalram=135030112256, freeram=18004209664, sharedram=3393691648, bufferram=2800984064, totalswap=31999389696, freeswap=16647667712, procs=4198, totalhigh=0, freehigh=0, mem_unit=1}) = 0
rt_sigaction(SIGCHLD, {sa_handler=SIG_DFL, sa_mask=[], sa_flags=SA_RESTORER|SA_RESTART, sa_restorer=0x7fa2e2a42520}, {sa_handler=SIG_DFL, sa_mask=[], sa_flags=0}, 8) = 0
rt_sigaction(SIGCHLD, {sa_handler=SIG_DFL, sa_mask=[], sa_flags=SA_RESTORER|SA_RESTART, sa_restorer=0x7fa2e2a42520}, {sa_handler=SIG_DFL, sa_mask=[], sa_flags=SA_RESTORER|SA_RESTART, sa_restorer=0x7fa2e2a42520}, 8) = 0
rt_sigaction(SIGINT, {sa_handler=SIG_DFL, sa_mask=[], sa_flags=SA_RESTORER, sa_restorer=0x7fa2e2a42520}, {sa_handler=SIG_DFL, sa_mask=[], sa_flags=0}, 8) = 0
rt_sigaction(SIGINT, {sa_handler=SIG_DFL, sa_mask=[], sa_flags=SA_RESTORER, sa_restorer=0x7fa2e2a42520}, {sa_handler=SIG_DFL, sa_mask=[], sa_flags=SA_RESTORER, sa_restorer=0x7fa2e2a42520}, 8) = 0
rt_sigaction(SIGQUIT, {sa_handler=SIG_DFL, sa_mask=[], sa_flags=SA_RESTORER, sa_restorer=0x7fa2e2a42520}, {sa_handler=SIG_DFL, sa_mask=[], sa_flags=0}, 8) = 0
rt_sigaction(SIGQUIT, {sa_handler=SIG_DFL, sa_mask=[], sa_flags=SA_RESTORER, sa_restorer=0x7fa2e2a42520}, {sa_handler=SIG_DFL, sa_mask=[], sa_flags=SA_RESTORER, sa_restorer=0x7fa2e2a42520}, 8) = 0
rt_sigaction(SIGTSTP, {sa_handler=SIG_DFL, sa_mask=[], sa_flags=SA_RESTORER, sa_restorer=0x7fa2e2a42520}, {sa_handler=SIG_DFL, sa_mask=[], sa_flags=0}, 8) = 0
rt_sigaction(SIGTSTP, {sa_handler=SIG_DFL, sa_mask=[], sa_flags=SA_RESTORER, sa_restorer=0x7fa2e2a42520}, {sa_handler=SIG_DFL, sa_mask=[], sa_flags=SA_RESTORER, sa_restorer=0x7fa2e2a42520}, 8) = 0
rt_sigaction(SIGTTIN, {sa_handler=SIG_DFL, sa_mask=[], sa_flags=SA_RESTORER, sa_restorer=0x7fa2e2a42520}, {sa_handler=SIG_DFL, sa_mask=[], sa_flags=0}, 8) = 0
rt_sigaction(SIGTTIN, {sa_handler=SIG_DFL, sa_mask=[], sa_flags=SA_RESTORER, sa_restorer=0x7fa2e2a42520}, {sa_handler=SIG_DFL, sa_mask=[], sa_flags=SA_RESTORER, sa_restorer=0x7fa2e2a42520}, 8) = 0
rt_sigaction(SIGTTOU, {sa_handler=SIG_DFL, sa_mask=[], sa_flags=SA_RESTORER, sa_restorer=0x7fa2e2a42520}, {sa_handler=SIG_DFL, sa_mask=[], sa_flags=0}, 8) = 0
rt_sigaction(SIGTTOU, {sa_handler=SIG_DFL, sa_mask=[], sa_flags=SA_RESTORER, sa_restorer=0x7fa2e2a42520}, {sa_handler=SIG_DFL, sa_mask=[], sa_flags=SA_RESTORER, sa_restorer=0x7fa2e2a42520}, 8) = 0
rt_sigprocmask(SIG_BLOCK, NULL, [], 8)  = 0
rt_sigaction(SIGQUIT, {sa_handler=SIG_IGN, sa_mask=[], sa_flags=SA_RESTORER, sa_restorer=0x7fa2e2a42520}, {sa_handler=SIG_DFL, sa_mask=[], sa_flags=SA_RESTORER, sa_restorer=0x7fa2e2a42520}, 8) = 0
uname({sysname="Linux", nodename="liubo-SYS-7048GR-TR", ...}) = 0
newfstatat(AT_FDCWD, "/home/zhangchen", {st_mode=S_IFDIR|0750, st_size=4096, ...}, 0) = 0
newfstatat(AT_FDCWD, ".", {st_mode=S_IFDIR|0750, st_size=4096, ...}, 0) = 0
newfstatat(AT_FDCWD, "/home", {st_mode=S_IFDIR|0755, st_size=4096, ...}, 0) = 0
newfstatat(AT_FDCWD, "/home/zhangchen", {st_mode=S_IFDIR|0750, st_size=4096, ...}, 0) = 0
getpid()                                = 4064924
getppid()                               = 4064921
newfstatat(AT_FDCWD, ".", {st_mode=S_IFDIR|0750, st_size=4096, ...}, 0) = 0
newfstatat(AT_FDCWD, "/home/zhangchen/.vscode-server/cli/servers/Stable-dc96b837cf6bb4af9cd736aa3af08cf8279f7685/server/bin/remote-cli/bash", 0x7fff3394aee0, 0) = -1 ENOENT (No such file or directory)
newfstatat(AT_FDCWD, "/home/zhangchen/.conda/envs/DL/bin/bash", 0x7fff3394aee0, 0) = -1 ENOENT (No such file or directory)
newfstatat(AT_FDCWD, "/opt/miniconda3/condabin/bash", 0x7fff3394aee0, 0) = -1 ENOENT (No such file or directory)
newfstatat(AT_FDCWD, "/opt/miniconda3/bin/bash", 0x7fff3394aee0, 0) = -1 ENOENT (No such file or directory)
newfstatat(AT_FDCWD, "/usr/local/sbin/bash", 0x7fff3394aee0, 0) = -1 ENOENT (No such file or directory)
newfstatat(AT_FDCWD, "/usr/local/bin/bash", 0x7fff3394aee0, 0) = -1 ENOENT (No such file or directory)
newfstatat(AT_FDCWD, "/usr/sbin/bash", 0x7fff3394aee0, 0) = -1 ENOENT (No such file or directory)
newfstatat(AT_FDCWD, "/usr/bin/bash", {st_mode=S_IFREG|0755, st_size=1396520, ...}, 0) = 0
newfstatat(AT_FDCWD, "/usr/bin/bash", {st_mode=S_IFREG|0755, st_size=1396520, ...}, 0) = 0
geteuid()                               = 1006
getegid()                               = 1002
getuid()                                = 1006
getgid()                                = 1002
access("/usr/bin/bash", X_OK)           = 0
newfstatat(AT_FDCWD, "/usr/bin/bash", {st_mode=S_IFREG|0755, st_size=1396520, ...}, 0) = 0
geteuid()                               = 1006
getegid()                               = 1002
getuid()                                = 1006
getgid()                                = 1002
access("/usr/bin/bash", R_OK)           = 0
newfstatat(AT_FDCWD, "/usr/bin/bash", {st_mode=S_IFREG|0755, st_size=1396520, ...}, 0) = 0
newfstatat(AT_FDCWD, "/usr/bin/bash", {st_mode=S_IFREG|0755, st_size=1396520, ...}, 0) = 0
geteuid()                               = 1006
getegid()                               = 1002
getuid()                                = 1006
getgid()                                = 1002
access("/usr/bin/bash", X_OK)           = 0
newfstatat(AT_FDCWD, "/usr/bin/bash", {st_mode=S_IFREG|0755, st_size=1396520, ...}, 0) = 0
geteuid()                               = 1006
getegid()                               = 1002
getuid()                                = 1006
getgid()                                = 1002
access("/usr/bin/bash", R_OK)           = 0
getpid()                                = 4064924
getppid()                               = 4064921
getpid()                                = 4064924
getppid()                               = 4064921
getpgrp()                               = 4064921
ioctl(2, TIOCGPGRP, [4064921])          = 0
rt_sigaction(SIGCHLD, {sa_handler=0x55cfdd0a9d10, sa_mask=[], sa_flags=SA_RESTORER|SA_RESTART, sa_restorer=0x7fa2e2a42520}, {sa_handler=SIG_DFL, sa_mask=[], sa_flags=SA_RESTORER|SA_RESTART, sa_restorer=0x7fa2e2a42520}, 8) = 0
prlimit64(0, RLIMIT_NPROC, NULL, {rlim_cur=514857, rlim_max=514857}) = 0
rt_sigprocmask(SIG_BLOCK, NULL, [], 8)  = 0
openat(AT_FDCWD, "test.sh", O_RDONLY)   = 3
newfstatat(AT_FDCWD, "test.sh", {st_mode=S_IFREG|0644, st_size=9, ...}, 0) = 0
ioctl(3, TCGETS, 0x7fff3394b240)        = -1 ENOTTY (Inappropriate ioctl for device)
lseek(3, 0, SEEK_CUR)                   = 0
read(3, "sleep 20\n", 80)               = 9
lseek(3, 0, SEEK_SET)                   = 0
prlimit64(0, RLIMIT_NOFILE, NULL, {rlim_cur=1024*1024, rlim_max=1024*1024}) = 0
fcntl(255, F_GETFD)                     = -1 EBADF (Bad file descriptor)
dup2(3, 255)                            = 255
close(3)                                = 0
fcntl(255, F_SETFD, FD_CLOEXEC)         = 0
fcntl(255, F_GETFL)                     = 0x8000 (flags O_RDONLY|O_LARGEFILE)
newfstatat(255, "", {st_mode=S_IFREG|0644, st_size=9, ...}, AT_EMPTY_PATH) = 0
lseek(255, 0, SEEK_CUR)                 = 0
read(255, "sleep 20\n", 9)              = 9
newfstatat(AT_FDCWD, ".", {st_mode=S_IFDIR|0750, st_size=4096, ...}, 0) = 0
newfstatat(AT_FDCWD, "/home/zhangchen/.vscode-server/cli/servers/Stable-dc96b837cf6bb4af9cd736aa3af08cf8279f7685/server/bin/remote-cli/sleep", 0x7fff3394ad30, 0) = -1 ENOENT (No such file or directory)
newfstatat(AT_FDCWD, "/home/zhangchen/.conda/envs/DL/bin/sleep", 0x7fff3394ad30, 0) = -1 ENOENT (No such file or directory)
newfstatat(AT_FDCWD, "/opt/miniconda3/condabin/sleep", 0x7fff3394ad30, 0) = -1 ENOENT (No such file or directory)
newfstatat(AT_FDCWD, "/opt/miniconda3/bin/sleep", 0x7fff3394ad30, 0) = -1 ENOENT (No such file or directory)
newfstatat(AT_FDCWD, "/usr/local/sbin/sleep", 0x7fff3394ad30, 0) = -1 ENOENT (No such file or directory)
newfstatat(AT_FDCWD, "/usr/local/bin/sleep", 0x7fff3394ad30, 0) = -1 ENOENT (No such file or directory)
newfstatat(AT_FDCWD, "/usr/sbin/sleep", 0x7fff3394ad30, 0) = -1 ENOENT (No such file or directory)
newfstatat(AT_FDCWD, "/usr/bin/sleep", {st_mode=S_IFREG|0755, st_size=35328, ...}, 0) = 0
newfstatat(AT_FDCWD, "/usr/bin/sleep", {st_mode=S_IFREG|0755, st_size=35328, ...}, 0) = 0
geteuid()                               = 1006
getegid()                               = 1002
getuid()                                = 1006
getgid()                                = 1002
access("/usr/bin/sleep", X_OK)          = 0
newfstatat(AT_FDCWD, "/usr/bin/sleep", {st_mode=S_IFREG|0755, st_size=35328, ...}, 0) = 0
geteuid()                               = 1006
getegid()                               = 1002
getuid()                                = 1006
getgid()                                = 1002
access("/usr/bin/sleep", R_OK)          = 0
newfstatat(AT_FDCWD, "/usr/bin/sleep", {st_mode=S_IFREG|0755, st_size=35328, ...}, 0) = 0
newfstatat(AT_FDCWD, "/usr/bin/sleep", {st_mode=S_IFREG|0755, st_size=35328, ...}, 0) = 0
geteuid()                               = 1006
getegid()                               = 1002
getuid()                                = 1006
getgid()                                = 1002
access("/usr/bin/sleep", X_OK)          = 0
newfstatat(AT_FDCWD, "/usr/bin/sleep", {st_mode=S_IFREG|0755, st_size=35328, ...}, 0) = 0
geteuid()                               = 1006
getegid()                               = 1002
getuid()                                = 1006
getgid()                                = 1002
access("/usr/bin/sleep", R_OK)          = 0
rt_sigprocmask(SIG_BLOCK, NULL, [], 8)  = 0
rt_sigprocmask(SIG_BLOCK, [INT TERM CHLD], [], 8) = 0
clone(child_stack=NULL, flags=CLONE_CHILD_CLEARTID|CLONE_CHILD_SETTID|SIGCHLD, child_tidptr=0x7fa2e2c5fa10) = 4064925
strace: Process 4064925 attached
[pid 4064924] rt_sigprocmask(SIG_SETMASK, [], NULL, 8) = 0
[pid 4064925] set_robust_list(0x7fa2e2c5fa20, 24) = 0
[pid 4064924] rt_sigprocmask(SIG_BLOCK, [CHLD], [], 8) = 0
[pid 4064925] getpid( <unfinished ...>
[pid 4064924] rt_sigprocmask(SIG_SETMASK, [],  <unfinished ...>
[pid 4064925] <... getpid resumed>)     = 4064925
[pid 4064924] <... rt_sigprocmask resumed>NULL, 8) = 0
[pid 4064924] rt_sigprocmask(SIG_BLOCK, [CHLD], [], 8) = 0
[pid 4064924] rt_sigaction(SIGINT, {sa_handler=0x55cfdd0abdc0, sa_mask=[], sa_flags=SA_RESTORER, sa_restorer=0x7fa2e2a42520},  <unfinished ...>
[pid 4064925] close(255 <unfinished ...>
[pid 4064924] <... rt_sigaction resumed>{sa_handler=SIG_DFL, sa_mask=[], sa_flags=SA_RESTORER, sa_restorer=0x7fa2e2a42520}, 8) = 0
[pid 4064925] <... close resumed>)      = 0
[pid 4064924] wait4(-1,  <unfinished ...>
[pid 4064925] rt_sigprocmask(SIG_SETMASK, [], NULL, 8) = 0
[pid 4064925] rt_sigaction(SIGTSTP, {sa_handler=SIG_DFL, sa_mask=[], sa_flags=SA_RESTORER, sa_restorer=0x7fa2e2a42520}, {sa_handler=SIG_DFL, sa_mask=[], sa_flags=SA_RESTORER, sa_restorer=0x7fa2e2a42520}, 8) = 0
[pid 4064925] rt_sigaction(SIGTTIN, {sa_handler=SIG_DFL, sa_mask=[], sa_flags=SA_RESTORER, sa_restorer=0x7fa2e2a42520}, {sa_handler=SIG_DFL, sa_mask=[], sa_flags=SA_RESTORER, sa_restorer=0x7fa2e2a42520}, 8) = 0
[pid 4064925] rt_sigaction(SIGTTOU, {sa_handler=SIG_DFL, sa_mask=[], sa_flags=SA_RESTORER, sa_restorer=0x7fa2e2a42520}, {sa_handler=SIG_DFL, sa_mask=[], sa_flags=SA_RESTORER, sa_restorer=0x7fa2e2a42520}, 8) = 0
[pid 4064925] rt_sigaction(SIGINT, {sa_handler=SIG_DFL, sa_mask=[], sa_flags=SA_RESTORER, sa_restorer=0x7fa2e2a42520}, {sa_handler=SIG_DFL, sa_mask=[], sa_flags=SA_RESTORER, sa_restorer=0x7fa2e2a42520}, 8) = 0
[pid 4064925] rt_sigaction(SIGQUIT, {sa_handler=SIG_DFL, sa_mask=[], sa_flags=SA_RESTORER, sa_restorer=0x7fa2e2a42520}, {sa_handler=SIG_IGN, sa_mask=[], sa_flags=SA_RESTORER, sa_restorer=0x7fa2e2a42520}, 8) = 0
[pid 4064925] rt_sigaction(SIGCHLD, {sa_handler=SIG_DFL, sa_mask=[], sa_flags=SA_RESTORER|SA_RESTART, sa_restorer=0x7fa2e2a42520}, {sa_handler=0x55cfdd0a9d10, sa_mask=[], sa_flags=SA_RESTORER|SA_RESTART, sa_restorer=0x7fa2e2a42520}, 8) = 0
[pid 4064925] execve("/usr/bin/sleep", ["sleep", "20"], 0x55cfde998b60 /* 54 vars */) = 0
[pid 4064925] brk(NULL)                 = 0x56531e557000
[pid 4064925] arch_prctl(0x3001 /* ARCH_??? */, 0x7fff4b839270) = -1 EINVAL (Invalid argument)
[pid 4064925] mmap(NULL, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f1758aa0000
[pid 4064925] access("/etc/ld.so.preload", R_OK) = -1 ENOENT (No such file or directory)
[pid 4064925] openat(AT_FDCWD, "/etc/ld.so.cache", O_RDONLY|O_CLOEXEC) = 3
[pid 4064925] newfstatat(3, "", {st_mode=S_IFREG|0644, st_size=95179, ...}, AT_EMPTY_PATH) = 0
[pid 4064925] mmap(NULL, 95179, PROT_READ, MAP_PRIVATE, 3, 0) = 0x7f1758a88000
[pid 4064925] close(3)                  = 0
[pid 4064925] openat(AT_FDCWD, "/lib/x86_64-linux-gnu/libc.so.6", O_RDONLY|O_CLOEXEC) = 3
[pid 4064925] read(3, "\177ELF\2\1\1\3\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0P\237\2\0\0\0\0\0"..., 832) = 832
[pid 4064925] pread64(3, "\6\0\0\0\4\0\0\0@\0\0\0\0\0\0\0@\0\0\0\0\0\0\0@\0\0\0\0\0\0\0"..., 784, 64) = 784
[pid 4064925] pread64(3, "\4\0\0\0 \0\0\0\5\0\0\0GNU\0\2\0\0\300\4\0\0\0\3\0\0\0\0\0\0\0"..., 48, 848) = 48
[pid 4064925] pread64(3, "\4\0\0\0\24\0\0\0\3\0\0\0GNU\0\302\211\332Pq\2439\235\350\223\322\257\201\326\243\f"..., 68, 896) = 68
[pid 4064925] newfstatat(3, "", {st_mode=S_IFREG|0755, st_size=2220400, ...}, AT_EMPTY_PATH) = 0
[pid 4064925] pread64(3, "\6\0\0\0\4\0\0\0@\0\0\0\0\0\0\0@\0\0\0\0\0\0\0@\0\0\0\0\0\0\0"..., 784, 64) = 784
[pid 4064925] mmap(NULL, 2264656, PROT_READ, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x7f1758800000
[pid 4064925] mprotect(0x7f1758828000, 2023424, PROT_NONE) = 0
[pid 4064925] mmap(0x7f1758828000, 1658880, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x28000) = 0x7f1758828000
[pid 4064925] mmap(0x7f17589bd000, 360448, PROT_READ, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x1bd000) = 0x7f17589bd000
[pid 4064925] mmap(0x7f1758a16000, 24576, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x215000) = 0x7f1758a16000
[pid 4064925] mmap(0x7f1758a1c000, 52816, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0x7f1758a1c000
[pid 4064925] close(3)                  = 0
[pid 4064925] mmap(NULL, 12288, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f1758a85000
[pid 4064925] arch_prctl(ARCH_SET_FS, 0x7f1758a85740) = 0
[pid 4064925] set_tid_address(0x7f1758a85a10) = 4064925
[pid 4064925] set_robust_list(0x7f1758a85a20, 24) = 0
[pid 4064925] rseq(0x7f1758a860e0, 0x20, 0, 0x53053053) = 0
[pid 4064925] mprotect(0x7f1758a16000, 16384, PROT_READ) = 0
[pid 4064925] mprotect(0x56531d334000, 4096, PROT_READ) = 0
[pid 4064925] mprotect(0x7f1758ada000, 8192, PROT_READ) = 0
[pid 4064925] prlimit64(0, RLIMIT_STACK, NULL, {rlim_cur=8192*1024, rlim_max=RLIM64_INFINITY}) = 0
[pid 4064925] munmap(0x7f1758a88000, 95179) = 0
[pid 4064925] getrandom("\xf0\x4d\x93\x81\xc9\x8a\x71\x74", 8, GRND_NONBLOCK) = 8
[pid 4064925] brk(NULL)                 = 0x56531e557000
[pid 4064925] brk(0x56531e578000)       = 0x56531e578000
[pid 4064925] openat(AT_FDCWD, "/usr/lib/locale/locale-archive", O_RDONLY|O_CLOEXEC) = 3
[pid 4064925] newfstatat(3, "", {st_mode=S_IFREG|0644, st_size=8872448, ...}, AT_EMPTY_PATH) = 0
[pid 4064925] mmap(NULL, 8872448, PROT_READ, MAP_PRIVATE, 3, 0) = 0x7f1757e00000
[pid 4064925] close(3)                  = 0
[pid 4064925] clock_nanosleep(CLOCK_REALTIME, 0, {tv_sec=20, tv_nsec=0}, 0x7fff4b8392c0) = 0
[pid 4064925] close(1)                  = 0
[pid 4064925] close(2)                  = 0
[pid 4064925] exit_group(0)             = ?
[pid 4064925] +++ exited with 0 +++
<... wait4 resumed>[{WIFEXITED(s) && WEXITSTATUS(s) == 0}], 0, NULL) = 4064925
rt_sigaction(SIGINT, {sa_handler=SIG_DFL, sa_mask=[], sa_flags=SA_RESTORER, sa_restorer=0x7fa2e2a42520}, {sa_handler=0x55cfdd0abdc0, sa_mask=[], sa_flags=SA_RESTORER, sa_restorer=0x7fa2e2a42520}, 8) = 0
ioctl(2, TIOCGWINSZ, {ws_row=32, ws_col=200, ws_xpixel=0, ws_ypixel=0}) = 0
ioctl(1, TCGETS, {B38400 opost isig icanon echo ...}) = 0
getuid()                                = 1006
geteuid()                               = 1006
getgid()                                = 1002
getegid()                               = 1002
getuid()                                = 1006
geteuid()                               = 1006
getgid()                                = 1002
getegid()                               = 1002
newfstatat(AT_FDCWD, "/home/zhangchen/.terminfo", 0x55cfde99f160, 0) = -1 ENOENT (No such file or directory)
newfstatat(AT_FDCWD, "/etc/terminfo", {st_mode=S_IFDIR|0755, st_size=4096, ...}, 0) = 0
newfstatat(AT_FDCWD, "/lib/terminfo", {st_mode=S_IFDIR|0755, st_size=4096, ...}, 0) = 0
newfstatat(AT_FDCWD, "/usr/share/terminfo", {st_mode=S_IFDIR|0755, st_size=4096, ...}, 0) = 0
access("/etc/terminfo/x/xterm-256color", R_OK) = -1 ENOENT (No such file or directory)
access("/lib/terminfo/x/xterm-256color", R_OK) = 0
openat(AT_FDCWD, "/lib/terminfo/x/xterm-256color", O_RDONLY) = 3
newfstatat(3, "", {st_mode=S_IFREG|0644, st_size=3852, ...}, AT_EMPTY_PATH) = 0
read(3, "\36\2%\0&\0\17\0\235\1Z\6xterm-256color|xterm"..., 32768) = 3852
read(3, "", 28672)                      = 0
close(3)                                = 0
ioctl(1, TCGETS, {B38400 opost isig icanon echo ...}) = 0
ioctl(1, TCGETS, {B38400 opost isig icanon echo ...}) = 0
ioctl(1, TCGETS, {B38400 opost isig icanon echo ...}) = 0
ioctl(1, TCGETS, {B38400 opost isig icanon echo ...}) = 0
ioctl(1, TIOCGWINSZ, {ws_row=32, ws_col=200, ws_xpixel=0, ws_ypixel=0}) = 0
ioctl(0, TIOCGWINSZ, {ws_row=32, ws_col=200, ws_xpixel=0, ws_ypixel=0}) = 0
brk(0x55cfde9c9000)                     = 0x55cfde9c9000
rt_sigprocmask(SIG_SETMASK, [], NULL, 8) = 0
--- SIGCHLD {si_signo=SIGCHLD, si_code=CLD_EXITED, si_pid=4064925, si_uid=1006, si_status=0, si_utime=0, si_stime=0} ---
wait4(-1, 0x7fff3394a810, WNOHANG, NULL) = -1 ECHILD (No child processes)
rt_sigreturn({mask=[]})                 = 0
read(255, "", 9)                        = 0
rt_sigprocmask(SIG_BLOCK, [CHLD], [], 8) = 0
rt_sigprocmask(SIG_SETMASK, [], NULL, 8) = 0
exit_group(0)                           = ?
+++ exited with 0 +++

        可以看出,strace的输出在最开始没有显示从终端内的bash创建strace子进程和strace进程创建子进程的过程(因为这一般不是我们关心的),而是从strace进程创建子进程后调用execve进行替换开始(替换为bash)。从其中的getpid()=4064924可以看出,该bash进程的PID为4064924。从getppid()=4064921可以看出,该bash进程父进程的PID为4064921,这是strace进程的PID,而strace进程的父进程是终端内运行的bash。

        其中的clone(****)=4064925,展现了bash进程在读取到了sleep命令后,创建了一个子进程,并且子进程的PID为4064925。后面的[pid 4064925] execve("/usr/bin/sleep", ["sleep", "20"], 0x556bf6f3bb60 /* 54 vars */)=0展示了该子进程进行替换的过程。上面的两步,导致了bash进程创建了一个sleep子进程。

        其中的[pid 4064925] exit_group(0)=?代表了sleep进程退出,而最后的exit_group(0)=?代表了bash进程退出。

        在运行strace命令时,我们可以在另一个终端利用ps命令观察到进程的创建情况,如下所示。

UID          PID    PPID  C STIME TTY          TIME CMD
zhangch+ 4064921 4064501  0 14:19 pts/20   00:00:00 strace -f bash test.sh
zhangch+ 4064924 4064921  0 14:19 pts/20   00:00:00 bash test.sh
zhangch+ 4064925 4064924  0 14:19 pts/20   00:00:00 sleep 20

二、subshell(子shell)

        什么是子shell,似乎从字面意思,就是利用bash命令创建了一个bash子进程,就像是上面的starce命令所做的那样,它创建了bash子进程并在bash子进程中又创建了一个sleep子进程。

        但其实子shell不是如此,它特指在某些情况下,bash解释器会创建子进程,但不进行替换的过程,这与利用bash命令创建了一个bash子进程是不同的,后者存在替换的过程。

        下面的这些情况,会导致创建子shell。

1、小括号():使用小括号包围的命令,会在子shell中进行执行(意思就是先创建子shell(没有替换过程),随后在子shell中再根据命令创建子进程(完整的两步))。

2、后台控制符&:使用&结尾的命令,会在子shell中进行执行。

3、管道控制符| :使用|连接的命令,会分别各自创建子shell并进行执行。

4、命令替换$():命令替换中的命令,是在子shell中进行执行。

4、coproc命令:这个命令会导致开启一个子shell,并执行后面的命令。

        需要注意的是,我们本文所说的所有命令都是外部命令,而不是shell内建命令,对于内建命令,不会用clone、execve创建进程,而是直接执行。可以使用type来检测一个命令是否为内建命令,如下所示。

$ type cd
cd is a shell builtin

         我们以小括号举例,将shell脚本修改为如下所示。注意到我们在小括号中添加了两条命令,这么做的原因后面会进行说明。

​# 文件test.sh(sleep 20;sleep 10)

        此时使用strace追踪的结果如下所示。 

execve("/usr/bin/bash", ["bash", "test.sh"], 0x7ffcd0c34cb0 /* 55 vars */) = 0
brk(NULL)                               = 0x5577b9e0f000
arch_prctl(0x3001 /* ARCH_??? */, 0x7fffb1f38ed0) = -1 EINVAL (Invalid argument)
mmap(NULL, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f584c4fd000
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
newfstatat(3, "", {st_mode=S_IFREG|0644, st_size=95179, ...}, AT_EMPTY_PATH) = 0
mmap(NULL, 95179, PROT_READ, MAP_PRIVATE, 3, 0) = 0x7f584c4e5000
close(3)                                = 0
openat(AT_FDCWD, "/lib/x86_64-linux-gnu/libtinfo.so.6", 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\0"..., 832) = 832
newfstatat(3, "", {st_mode=S_IFREG|0644, st_size=200136, ...}, AT_EMPTY_PATH) = 0
mmap(NULL, 203040, PROT_READ, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x7f584c4b3000
mmap(0x7f584c4c1000, 69632, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0xe000) = 0x7f584c4c1000
mmap(0x7f584c4d2000, 57344, PROT_READ, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x1f000) = 0x7f584c4d2000
mmap(0x7f584c4e0000, 20480, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x2c000) = 0x7f584c4e0000
close(3)                                = 0
openat(AT_FDCWD, "/lib/x86_64-linux-gnu/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\0P\237\2\0\0\0\0\0"..., 832) = 832
pread64(3, "\6\0\0\0\4\0\0\0@\0\0\0\0\0\0\0@\0\0\0\0\0\0\0@\0\0\0\0\0\0\0"..., 784, 64) = 784
pread64(3, "\4\0\0\0 \0\0\0\5\0\0\0GNU\0\2\0\0\300\4\0\0\0\3\0\0\0\0\0\0\0"..., 48, 848) = 48
pread64(3, "\4\0\0\0\24\0\0\0\3\0\0\0GNU\0\302\211\332Pq\2439\235\350\223\322\257\201\326\243\f"..., 68, 896) = 68
newfstatat(3, "", {st_mode=S_IFREG|0755, st_size=2220400, ...}, AT_EMPTY_PATH) = 0
pread64(3, "\6\0\0\0\4\0\0\0@\0\0\0\0\0\0\0@\0\0\0\0\0\0\0@\0\0\0\0\0\0\0"..., 784, 64) = 784
mmap(NULL, 2264656, PROT_READ, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x7f584c200000
mprotect(0x7f584c228000, 2023424, PROT_NONE) = 0
mmap(0x7f584c228000, 1658880, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x28000) = 0x7f584c228000
mmap(0x7f584c3bd000, 360448, PROT_READ, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x1bd000) = 0x7f584c3bd000
mmap(0x7f584c416000, 24576, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x215000) = 0x7f584c416000
mmap(0x7f584c41c000, 52816, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0x7f584c41c000
close(3)                                = 0
mmap(NULL, 12288, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f584c4b0000
arch_prctl(ARCH_SET_FS, 0x7f584c4b0740) = 0
set_tid_address(0x7f584c4b0a10)         = 649416
set_robust_list(0x7f584c4b0a20, 24)     = 0
rseq(0x7f584c4b10e0, 0x20, 0, 0x53053053) = 0
mprotect(0x7f584c416000, 16384, PROT_READ) = 0
mprotect(0x7f584c4e0000, 16384, PROT_READ) = 0
mprotect(0x5577b9661000, 16384, PROT_READ) = 0
mprotect(0x7f584c537000, 8192, PROT_READ) = 0
prlimit64(0, RLIMIT_STACK, NULL, {rlim_cur=8192*1024, rlim_max=RLIM64_INFINITY}) = 0
munmap(0x7f584c4e5000, 95179)           = 0
openat(AT_FDCWD, "/dev/tty", O_RDWR|O_NONBLOCK) = 3
close(3)                                = 0
getrandom("\xaf\x8b\x4d\x62\x2c\xae\x8f\x65", 8, GRND_NONBLOCK) = 8
brk(NULL)                               = 0x5577b9e0f000
brk(0x5577b9e30000)                     = 0x5577b9e30000
openat(AT_FDCWD, "/usr/lib/locale/locale-archive", O_RDONLY|O_CLOEXEC) = 3
newfstatat(3, "", {st_mode=S_IFREG|0644, st_size=8872448, ...}, AT_EMPTY_PATH) = 0
mmap(NULL, 8872448, PROT_READ, MAP_PRIVATE, 3, 0) = 0x7f584b800000
close(3)                                = 0
openat(AT_FDCWD, "/usr/lib/x86_64-linux-gnu/gconv/gconv-modules.cache", O_RDONLY) = 3
newfstatat(3, "", {st_mode=S_IFREG|0644, st_size=27002, ...}, AT_EMPTY_PATH) = 0
mmap(NULL, 27002, PROT_READ, MAP_SHARED, 3, 0) = 0x7f584c4f6000
close(3)                                = 0
futex(0x7f584c41ba6c, FUTEX_WAKE_PRIVATE, 2147483647) = 0
getuid()                                = 1006
getgid()                                = 1002
geteuid()                               = 1006
getegid()                               = 1002
rt_sigprocmask(SIG_BLOCK, NULL, [], 8)  = 0
ioctl(-1, TIOCGPGRP, 0x7fffb1f38dc4)    = -1 EBADF (Bad file descriptor)
sysinfo({uptime=7261723, loads=[40352, 39168, 38336], totalram=135030112256, freeram=18767388672, sharedram=3393511424, bufferram=2823208960, totalswap=31999389696, freeswap=16653172736, procs=4076, totalhigh=0, freehigh=0, mem_unit=1}) = 0
rt_sigaction(SIGCHLD, {sa_handler=SIG_DFL, sa_mask=[], sa_flags=SA_RESTORER|SA_RESTART, sa_restorer=0x7f584c242520}, {sa_handler=SIG_DFL, sa_mask=[], sa_flags=0}, 8) = 0
rt_sigaction(SIGCHLD, {sa_handler=SIG_DFL, sa_mask=[], sa_flags=SA_RESTORER|SA_RESTART, sa_restorer=0x7f584c242520}, {sa_handler=SIG_DFL, sa_mask=[], sa_flags=SA_RESTORER|SA_RESTART, sa_restorer=0x7f584c242520}, 8) = 0
rt_sigaction(SIGINT, {sa_handler=SIG_DFL, sa_mask=[], sa_flags=SA_RESTORER, sa_restorer=0x7f584c242520}, {sa_handler=SIG_DFL, sa_mask=[], sa_flags=0}, 8) = 0
rt_sigaction(SIGINT, {sa_handler=SIG_DFL, sa_mask=[], sa_flags=SA_RESTORER, sa_restorer=0x7f584c242520}, {sa_handler=SIG_DFL, sa_mask=[], sa_flags=SA_RESTORER, sa_restorer=0x7f584c242520}, 8) = 0
rt_sigaction(SIGQUIT, {sa_handler=SIG_DFL, sa_mask=[], sa_flags=SA_RESTORER, sa_restorer=0x7f584c242520}, {sa_handler=SIG_DFL, sa_mask=[], sa_flags=0}, 8) = 0
rt_sigaction(SIGQUIT, {sa_handler=SIG_DFL, sa_mask=[], sa_flags=SA_RESTORER, sa_restorer=0x7f584c242520}, {sa_handler=SIG_DFL, sa_mask=[], sa_flags=SA_RESTORER, sa_restorer=0x7f584c242520}, 8) = 0
rt_sigaction(SIGTSTP, {sa_handler=SIG_DFL, sa_mask=[], sa_flags=SA_RESTORER, sa_restorer=0x7f584c242520}, {sa_handler=SIG_DFL, sa_mask=[], sa_flags=0}, 8) = 0
rt_sigaction(SIGTSTP, {sa_handler=SIG_DFL, sa_mask=[], sa_flags=SA_RESTORER, sa_restorer=0x7f584c242520}, {sa_handler=SIG_DFL, sa_mask=[], sa_flags=SA_RESTORER, sa_restorer=0x7f584c242520}, 8) = 0
rt_sigaction(SIGTTIN, {sa_handler=SIG_DFL, sa_mask=[], sa_flags=SA_RESTORER, sa_restorer=0x7f584c242520}, {sa_handler=SIG_DFL, sa_mask=[], sa_flags=0}, 8) = 0
rt_sigaction(SIGTTIN, {sa_handler=SIG_DFL, sa_mask=[], sa_flags=SA_RESTORER, sa_restorer=0x7f584c242520}, {sa_handler=SIG_DFL, sa_mask=[], sa_flags=SA_RESTORER, sa_restorer=0x7f584c242520}, 8) = 0
rt_sigaction(SIGTTOU, {sa_handler=SIG_DFL, sa_mask=[], sa_flags=SA_RESTORER, sa_restorer=0x7f584c242520}, {sa_handler=SIG_DFL, sa_mask=[], sa_flags=0}, 8) = 0
rt_sigaction(SIGTTOU, {sa_handler=SIG_DFL, sa_mask=[], sa_flags=SA_RESTORER, sa_restorer=0x7f584c242520}, {sa_handler=SIG_DFL, sa_mask=[], sa_flags=SA_RESTORER, sa_restorer=0x7f584c242520}, 8) = 0
rt_sigprocmask(SIG_BLOCK, NULL, [], 8)  = 0
rt_sigaction(SIGQUIT, {sa_handler=SIG_IGN, sa_mask=[], sa_flags=SA_RESTORER, sa_restorer=0x7f584c242520}, {sa_handler=SIG_DFL, sa_mask=[], sa_flags=SA_RESTORER, sa_restorer=0x7f584c242520}, 8) = 0
uname({sysname="Linux", nodename="liubo-SYS-7048GR-TR", ...}) = 0
newfstatat(AT_FDCWD, "/home/zhangchen", {st_mode=S_IFDIR|0750, st_size=4096, ...}, 0) = 0
newfstatat(AT_FDCWD, ".", {st_mode=S_IFDIR|0750, st_size=4096, ...}, 0) = 0
newfstatat(AT_FDCWD, "/home", {st_mode=S_IFDIR|0755, st_size=4096, ...}, 0) = 0
newfstatat(AT_FDCWD, "/home/zhangchen", {st_mode=S_IFDIR|0750, st_size=4096, ...}, 0) = 0
getpid()                                = 649416
getppid()                               = 649413
newfstatat(AT_FDCWD, ".", {st_mode=S_IFDIR|0750, st_size=4096, ...}, 0) = 0
newfstatat(AT_FDCWD, "/home/zhangchen/.vscode-server/cli/servers/Stable-dc96b837cf6bb4af9cd736aa3af08cf8279f7685/server/bin/remote-cli/bash", 0x7fffb1f38a00, 0) = -1 ENOENT (No such file or directory)
newfstatat(AT_FDCWD, "/home/zhangchen/.conda/envs/DL/bin/bash", 0x7fffb1f38a00, 0) = -1 ENOENT (No such file or directory)
newfstatat(AT_FDCWD, "/opt/miniconda3/condabin/bash", 0x7fffb1f38a00, 0) = -1 ENOENT (No such file or directory)
newfstatat(AT_FDCWD, "/opt/miniconda3/bin/bash", 0x7fffb1f38a00, 0) = -1 ENOENT (No such file or directory)
newfstatat(AT_FDCWD, "/usr/local/sbin/bash", 0x7fffb1f38a00, 0) = -1 ENOENT (No such file or directory)
newfstatat(AT_FDCWD, "/usr/local/bin/bash", 0x7fffb1f38a00, 0) = -1 ENOENT (No such file or directory)
newfstatat(AT_FDCWD, "/usr/sbin/bash", 0x7fffb1f38a00, 0) = -1 ENOENT (No such file or directory)
newfstatat(AT_FDCWD, "/usr/bin/bash", {st_mode=S_IFREG|0755, st_size=1396520, ...}, 0) = 0
newfstatat(AT_FDCWD, "/usr/bin/bash", {st_mode=S_IFREG|0755, st_size=1396520, ...}, 0) = 0
geteuid()                               = 1006
getegid()                               = 1002
getuid()                                = 1006
getgid()                                = 1002
access("/usr/bin/bash", X_OK)           = 0
newfstatat(AT_FDCWD, "/usr/bin/bash", {st_mode=S_IFREG|0755, st_size=1396520, ...}, 0) = 0
geteuid()                               = 1006
getegid()                               = 1002
getuid()                                = 1006
getgid()                                = 1002
access("/usr/bin/bash", R_OK)           = 0
newfstatat(AT_FDCWD, "/usr/bin/bash", {st_mode=S_IFREG|0755, st_size=1396520, ...}, 0) = 0
newfstatat(AT_FDCWD, "/usr/bin/bash", {st_mode=S_IFREG|0755, st_size=1396520, ...}, 0) = 0
geteuid()                               = 1006
getegid()                               = 1002
getuid()                                = 1006
getgid()                                = 1002
access("/usr/bin/bash", X_OK)           = 0
newfstatat(AT_FDCWD, "/usr/bin/bash", {st_mode=S_IFREG|0755, st_size=1396520, ...}, 0) = 0
geteuid()                               = 1006
getegid()                               = 1002
getuid()                                = 1006
getgid()                                = 1002
access("/usr/bin/bash", R_OK)           = 0
getpid()                                = 649416
getppid()                               = 649413
getpid()                                = 649416
getppid()                               = 649413
getpgrp()                               = 649413
ioctl(2, TIOCGPGRP, [649413])           = 0
rt_sigaction(SIGCHLD, {sa_handler=0x5577b9576d10, sa_mask=[], sa_flags=SA_RESTORER|SA_RESTART, sa_restorer=0x7f584c242520}, {sa_handler=SIG_DFL, sa_mask=[], sa_flags=SA_RESTORER|SA_RESTART, sa_restorer=0x7f584c242520}, 8) = 0
prlimit64(0, RLIMIT_NPROC, NULL, {rlim_cur=514857, rlim_max=514857}) = 0
rt_sigprocmask(SIG_BLOCK, NULL, [], 8)  = 0
openat(AT_FDCWD, "test.sh", O_RDONLY)   = 3
newfstatat(AT_FDCWD, "test.sh", {st_mode=S_IFREG|0777, st_size=20, ...}, 0) = 0
ioctl(3, TCGETS, 0x7fffb1f38d60)        = -1 ENOTTY (Inappropriate ioctl for device)
lseek(3, 0, SEEK_CUR)                   = 0
read(3, "(sleep 20;sleep 10)\n", 80)    = 20
lseek(3, 0, SEEK_SET)                   = 0
prlimit64(0, RLIMIT_NOFILE, NULL, {rlim_cur=1024*1024, rlim_max=1024*1024}) = 0
fcntl(255, F_GETFD)                     = -1 EBADF (Bad file descriptor)
dup2(3, 255)                            = 255
close(3)                                = 0
fcntl(255, F_SETFD, FD_CLOEXEC)         = 0
fcntl(255, F_GETFL)                     = 0x8000 (flags O_RDONLY|O_LARGEFILE)
newfstatat(255, "", {st_mode=S_IFREG|0777, st_size=20, ...}, AT_EMPTY_PATH) = 0
lseek(255, 0, SEEK_CUR)                 = 0
read(255, "(sleep 20;sleep 10)\n", 20)  = 20
rt_sigprocmask(SIG_BLOCK, NULL, [], 8)  = 0
rt_sigprocmask(SIG_BLOCK, [INT TERM CHLD], [], 8) = 0
clone(child_stack=NULL, flags=CLONE_CHILD_CLEARTID|CLONE_CHILD_SETTID|SIGCHLD, child_tidptr=0x7f584c4b0a10) = 649417
strace: Process 649417 attached
[pid 649416] rt_sigprocmask(SIG_SETMASK, [],  <unfinished ...>
[pid 649417] set_robust_list(0x7f584c4b0a20, 24 <unfinished ...>
[pid 649416] <... rt_sigprocmask resumed>NULL, 8) = 0
[pid 649417] <... set_robust_list resumed>) = 0
[pid 649416] rt_sigprocmask(SIG_BLOCK, [CHLD], [], 8) = 0
[pid 649416] rt_sigprocmask(SIG_SETMASK, [],  <unfinished ...>
[pid 649417] getpid( <unfinished ...>
[pid 649416] <... rt_sigprocmask resumed>NULL, 8) = 0
[pid 649417] <... getpid resumed>)      = 649417
[pid 649416] rt_sigprocmask(SIG_BLOCK, [CHLD], [], 8) = 0
[pid 649416] rt_sigaction(SIGINT, {sa_handler=0x5577b9578dc0, sa_mask=[], sa_flags=SA_RESTORER, sa_restorer=0x7f584c242520},  <unfinished ...>
[pid 649417] close(255 <unfinished ...>
[pid 649416] <... rt_sigaction resumed>{sa_handler=SIG_DFL, sa_mask=[], sa_flags=SA_RESTORER, sa_restorer=0x7f584c242520}, 8) = 0
[pid 649417] <... close resumed>)       = 0
[pid 649416] wait4(-1,  <unfinished ...>
[pid 649417] rt_sigprocmask(SIG_SETMASK, [], NULL, 8) = 0
[pid 649417] rt_sigaction(SIGTSTP, {sa_handler=SIG_DFL, sa_mask=[], sa_flags=SA_RESTORER, sa_restorer=0x7f584c242520}, {sa_handler=SIG_DFL, sa_mask=[], sa_flags=SA_RESTORER, sa_restorer=0x7f584c242520}, 8) = 0
[pid 649417] rt_sigaction(SIGTTIN, {sa_handler=SIG_DFL, sa_mask=[], sa_flags=SA_RESTORER, sa_restorer=0x7f584c242520}, {sa_handler=SIG_DFL, sa_mask=[], sa_flags=SA_RESTORER, sa_restorer=0x7f584c242520}, 8) = 0
[pid 649417] rt_sigaction(SIGTTOU, {sa_handler=SIG_DFL, sa_mask=[], sa_flags=SA_RESTORER, sa_restorer=0x7f584c242520}, {sa_handler=SIG_DFL, sa_mask=[], sa_flags=SA_RESTORER, sa_restorer=0x7f584c242520}, 8) = 0
[pid 649417] rt_sigaction(SIGINT, {sa_handler=SIG_DFL, sa_mask=[], sa_flags=SA_RESTORER, sa_restorer=0x7f584c242520}, {sa_handler=SIG_DFL, sa_mask=[], sa_flags=SA_RESTORER, sa_restorer=0x7f584c242520}, 8) = 0
[pid 649417] rt_sigaction(SIGQUIT, {sa_handler=SIG_DFL, sa_mask=[], sa_flags=SA_RESTORER, sa_restorer=0x7f584c242520}, {sa_handler=SIG_IGN, sa_mask=[], sa_flags=SA_RESTORER, sa_restorer=0x7f584c242520}, 8) = 0
[pid 649417] rt_sigaction(SIGCHLD, {sa_handler=SIG_DFL, sa_mask=[], sa_flags=SA_RESTORER|SA_RESTART, sa_restorer=0x7f584c242520}, {sa_handler=0x5577b9576d10, sa_mask=[], sa_flags=SA_RESTORER|SA_RESTART, sa_restorer=0x7f584c242520}, 8) = 0
[pid 649417] rt_sigaction(SIGINT, {sa_handler=0x5577b95a3410, sa_mask=[], sa_flags=SA_RESTORER, sa_restorer=0x7f584c242520}, {sa_handler=SIG_DFL, sa_mask=[], sa_flags=SA_RESTORER, sa_restorer=0x7f584c242520}, 8) = 0
[pid 649417] rt_sigaction(SIGCHLD, {sa_handler=0x5577b9576d10, sa_mask=[], sa_flags=SA_RESTORER|SA_RESTART, sa_restorer=0x7f584c242520}, {sa_handler=SIG_DFL, sa_mask=[], sa_flags=SA_RESTORER|SA_RESTART, sa_restorer=0x7f584c242520}, 8) = 0
[pid 649417] rt_sigprocmask(SIG_BLOCK, [CHLD], [], 8) = 0
[pid 649417] rt_sigprocmask(SIG_SETMASK, [], NULL, 8) = 0
[pid 649417] newfstatat(AT_FDCWD, ".", {st_mode=S_IFDIR|0750, st_size=4096, ...}, 0) = 0
[pid 649417] newfstatat(AT_FDCWD, "/home/zhangchen/.vscode-server/cli/servers/Stable-dc96b837cf6bb4af9cd736aa3af08cf8279f7685/server/bin/remote-cli/sleep", 0x7fffb1f385a0, 0) = -1 ENOENT (No such file or directory)
[pid 649417] newfstatat(AT_FDCWD, "/home/zhangchen/.conda/envs/DL/bin/sleep", 0x7fffb1f385a0, 0) = -1 ENOENT (No such file or directory)
[pid 649417] newfstatat(AT_FDCWD, "/opt/miniconda3/condabin/sleep", 0x7fffb1f385a0, 0) = -1 ENOENT (No such file or directory)
[pid 649417] newfstatat(AT_FDCWD, "/opt/miniconda3/bin/sleep", 0x7fffb1f385a0, 0) = -1 ENOENT (No such file or directory)
[pid 649417] newfstatat(AT_FDCWD, "/usr/local/sbin/sleep", 0x7fffb1f385a0, 0) = -1 ENOENT (No such file or directory)
[pid 649417] newfstatat(AT_FDCWD, "/usr/local/bin/sleep", 0x7fffb1f385a0, 0) = -1 ENOENT (No such file or directory)
[pid 649417] newfstatat(AT_FDCWD, "/usr/sbin/sleep", 0x7fffb1f385a0, 0) = -1 ENOENT (No such file or directory)
[pid 649417] newfstatat(AT_FDCWD, "/usr/bin/sleep", {st_mode=S_IFREG|0755, st_size=35328, ...}, 0) = 0
[pid 649417] newfstatat(AT_FDCWD, "/usr/bin/sleep", {st_mode=S_IFREG|0755, st_size=35328, ...}, 0) = 0
[pid 649417] geteuid()                  = 1006
[pid 649417] getegid()                  = 1002
[pid 649417] getuid()                   = 1006
[pid 649417] getgid()                   = 1002
[pid 649417] access("/usr/bin/sleep", X_OK) = 0
[pid 649417] newfstatat(AT_FDCWD, "/usr/bin/sleep", {st_mode=S_IFREG|0755, st_size=35328, ...}, 0) = 0
[pid 649417] geteuid()                  = 1006
[pid 649417] getegid()                  = 1002
[pid 649417] getuid()                   = 1006
[pid 649417] getgid()                   = 1002
[pid 649417] access("/usr/bin/sleep", R_OK) = 0
[pid 649417] newfstatat(AT_FDCWD, "/usr/bin/sleep", {st_mode=S_IFREG|0755, st_size=35328, ...}, 0) = 0
[pid 649417] newfstatat(AT_FDCWD, "/usr/bin/sleep", {st_mode=S_IFREG|0755, st_size=35328, ...}, 0) = 0
[pid 649417] geteuid()                  = 1006
[pid 649417] getegid()                  = 1002
[pid 649417] getuid()                   = 1006
[pid 649417] getgid()                   = 1002
[pid 649417] access("/usr/bin/sleep", X_OK) = 0
[pid 649417] newfstatat(AT_FDCWD, "/usr/bin/sleep", {st_mode=S_IFREG|0755, st_size=35328, ...}, 0) = 0
[pid 649417] geteuid()                  = 1006
[pid 649417] getegid()                  = 1002
[pid 649417] getuid()                   = 1006
[pid 649417] getgid()                   = 1002
[pid 649417] access("/usr/bin/sleep", R_OK) = 0
[pid 649417] rt_sigprocmask(SIG_BLOCK, NULL, [], 8) = 0
[pid 649417] rt_sigprocmask(SIG_BLOCK, [INT TERM CHLD], [], 8) = 0
[pid 649417] clone(child_stack=NULL, flags=CLONE_CHILD_CLEARTID|CLONE_CHILD_SETTID|SIGCHLD, child_tidptr=0x7f584c4b0a10) = 649418
strace: Process 649418 attached
[pid 649417] rt_sigprocmask(SIG_SETMASK, [],  <unfinished ...>
[pid 649418] set_robust_list(0x7f584c4b0a20, 24 <unfinished ...>
[pid 649417] <... rt_sigprocmask resumed>NULL, 8) = 0
[pid 649418] <... set_robust_list resumed>) = 0
[pid 649417] rt_sigprocmask(SIG_BLOCK, [CHLD],  <unfinished ...>
[pid 649418] getpid( <unfinished ...>
[pid 649417] <... rt_sigprocmask resumed>[], 8) = 0
[pid 649418] <... getpid resumed>)      = 649418
[pid 649417] rt_sigprocmask(SIG_SETMASK, [],  <unfinished ...>
[pid 649418] rt_sigprocmask(SIG_SETMASK, [],  <unfinished ...>
[pid 649417] <... rt_sigprocmask resumed>NULL, 8) = 0
[pid 649418] <... rt_sigprocmask resumed>NULL, 8) = 0
[pid 649417] rt_sigprocmask(SIG_BLOCK, [CHLD],  <unfinished ...>
[pid 649418] rt_sigaction(SIGTSTP, {sa_handler=SIG_DFL, sa_mask=[], sa_flags=SA_RESTORER, sa_restorer=0x7f584c242520},  <unfinished ...>
[pid 649417] <... rt_sigprocmask resumed>[], 8) = 0
[pid 649418] <... rt_sigaction resumed>{sa_handler=SIG_DFL, sa_mask=[], sa_flags=SA_RESTORER, sa_restorer=0x7f584c242520}, 8) = 0
[pid 649417] rt_sigaction(SIGINT, {sa_handler=0x5577b9578dc0, sa_mask=[], sa_flags=SA_RESTORER, sa_restorer=0x7f584c242520},  <unfinished ...>
[pid 649418] rt_sigaction(SIGTTIN, {sa_handler=SIG_DFL, sa_mask=[], sa_flags=SA_RESTORER, sa_restorer=0x7f584c242520},  <unfinished ...>
[pid 649417] <... rt_sigaction resumed>{sa_handler=0x5577b95a3410, sa_mask=[], sa_flags=SA_RESTORER, sa_restorer=0x7f584c242520}, 8) = 0
[pid 649418] <... rt_sigaction resumed>{sa_handler=SIG_DFL, sa_mask=[], sa_flags=SA_RESTORER, sa_restorer=0x7f584c242520}, 8) = 0
[pid 649417] wait4(-1,  <unfinished ...>
[pid 649418] rt_sigaction(SIGTTOU, {sa_handler=SIG_DFL, sa_mask=[], sa_flags=SA_RESTORER, sa_restorer=0x7f584c242520}, {sa_handler=SIG_DFL, sa_mask=[], sa_flags=SA_RESTORER, sa_restorer=0x7f584c242520}, 8) = 0
[pid 649418] rt_sigaction(SIGINT, {sa_handler=SIG_DFL, sa_mask=[], sa_flags=SA_RESTORER, sa_restorer=0x7f584c242520}, {sa_handler=0x5577b95a3410, sa_mask=[], sa_flags=SA_RESTORER, sa_restorer=0x7f584c242520}, 8) = 0
[pid 649418] rt_sigaction(SIGQUIT, {sa_handler=SIG_DFL, sa_mask=[], sa_flags=SA_RESTORER, sa_restorer=0x7f584c242520}, {sa_handler=SIG_DFL, sa_mask=[], sa_flags=SA_RESTORER, sa_restorer=0x7f584c242520}, 8) = 0
[pid 649418] rt_sigaction(SIGCHLD, {sa_handler=SIG_DFL, sa_mask=[], sa_flags=SA_RESTORER|SA_RESTART, sa_restorer=0x7f584c242520}, {sa_handler=0x5577b9576d10, sa_mask=[], sa_flags=SA_RESTORER|SA_RESTART, sa_restorer=0x7f584c242520}, 8) = 0
[pid 649418] execve("/usr/bin/sleep", ["sleep", "20"], 0x5577b9e20b60 /* 54 vars */) = 0
[pid 649418] brk(NULL)                  = 0x5561fa911000
[pid 649418] arch_prctl(0x3001 /* ARCH_??? */, 0x7ffc69f99ce0) = -1 EINVAL (Invalid argument)
[pid 649418] mmap(NULL, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f554a9ee000
[pid 649418] access("/etc/ld.so.preload", R_OK) = -1 ENOENT (No such file or directory)
[pid 649418] openat(AT_FDCWD, "/etc/ld.so.cache", O_RDONLY|O_CLOEXEC) = 3
[pid 649418] newfstatat(3, "", {st_mode=S_IFREG|0644, st_size=95179, ...}, AT_EMPTY_PATH) = 0
[pid 649418] mmap(NULL, 95179, PROT_READ, MAP_PRIVATE, 3, 0) = 0x7f554a9d6000
[pid 649418] close(3)                   = 0
[pid 649418] openat(AT_FDCWD, "/lib/x86_64-linux-gnu/libc.so.6", O_RDONLY|O_CLOEXEC) = 3
[pid 649418] read(3, "\177ELF\2\1\1\3\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0P\237\2\0\0\0\0\0"..., 832) = 832
[pid 649418] pread64(3, "\6\0\0\0\4\0\0\0@\0\0\0\0\0\0\0@\0\0\0\0\0\0\0@\0\0\0\0\0\0\0"..., 784, 64) = 784
[pid 649418] pread64(3, "\4\0\0\0 \0\0\0\5\0\0\0GNU\0\2\0\0\300\4\0\0\0\3\0\0\0\0\0\0\0"..., 48, 848) = 48
[pid 649418] pread64(3, "\4\0\0\0\24\0\0\0\3\0\0\0GNU\0\302\211\332Pq\2439\235\350\223\322\257\201\326\243\f"..., 68, 896) = 68
[pid 649418] newfstatat(3, "", {st_mode=S_IFREG|0755, st_size=2220400, ...}, AT_EMPTY_PATH) = 0
[pid 649418] pread64(3, "\6\0\0\0\4\0\0\0@\0\0\0\0\0\0\0@\0\0\0\0\0\0\0@\0\0\0\0\0\0\0"..., 784, 64) = 784
[pid 649418] mmap(NULL, 2264656, PROT_READ, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x7f554a600000
[pid 649418] mprotect(0x7f554a628000, 2023424, PROT_NONE) = 0
[pid 649418] mmap(0x7f554a628000, 1658880, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x28000) = 0x7f554a628000
[pid 649418] mmap(0x7f554a7bd000, 360448, PROT_READ, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x1bd000) = 0x7f554a7bd000
[pid 649418] mmap(0x7f554a816000, 24576, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x215000) = 0x7f554a816000
[pid 649418] mmap(0x7f554a81c000, 52816, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0x7f554a81c000
[pid 649418] close(3)                   = 0
[pid 649418] mmap(NULL, 12288, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f554a9d3000
[pid 649418] arch_prctl(ARCH_SET_FS, 0x7f554a9d3740) = 0
[pid 649418] set_tid_address(0x7f554a9d3a10) = 649418
[pid 649418] set_robust_list(0x7f554a9d3a20, 24) = 0
[pid 649418] rseq(0x7f554a9d40e0, 0x20, 0, 0x53053053) = 0
[pid 649418] mprotect(0x7f554a816000, 16384, PROT_READ) = 0
[pid 649418] mprotect(0x5561f8e6f000, 4096, PROT_READ) = 0
[pid 649418] mprotect(0x7f554aa28000, 8192, PROT_READ) = 0
[pid 649418] prlimit64(0, RLIMIT_STACK, NULL, {rlim_cur=8192*1024, rlim_max=RLIM64_INFINITY}) = 0
[pid 649418] munmap(0x7f554a9d6000, 95179) = 0
[pid 649418] getrandom("\xe2\xdf\xc1\x0c\x9a\xb3\xb1\x8c", 8, GRND_NONBLOCK) = 8
[pid 649418] brk(NULL)                  = 0x5561fa911000
[pid 649418] brk(0x5561fa932000)        = 0x5561fa932000
[pid 649418] openat(AT_FDCWD, "/usr/lib/locale/locale-archive", O_RDONLY|O_CLOEXEC) = 3
[pid 649418] newfstatat(3, "", {st_mode=S_IFREG|0644, st_size=8872448, ...}, AT_EMPTY_PATH) = 0
[pid 649418] mmap(NULL, 8872448, PROT_READ, MAP_PRIVATE, 3, 0) = 0x7f5549c00000
[pid 649418] close(3)                   = 0
[pid 649418] clock_nanosleep(CLOCK_REALTIME, 0, {tv_sec=20, tv_nsec=0}, 0x7ffc69f99d30) = 0
[pid 649418] close(1)                   = 0
[pid 649418] close(2)                   = 0
[pid 649418] exit_group(0)              = ?
[pid 649418] +++ exited with 0 +++
[pid 649417] <... wait4 resumed>[{WIFEXITED(s) && WEXITSTATUS(s) == 0}], 0, NULL) = 649418
[pid 649417] rt_sigaction(SIGINT, {sa_handler=0x5577b95a3410, sa_mask=[], sa_flags=SA_RESTORER, sa_restorer=0x7f584c242520}, {sa_handler=0x5577b9578dc0, sa_mask=[], sa_flags=SA_RESTORER, sa_restorer=0x7f584c242520}, 8) = 0
[pid 649417] rt_sigprocmask(SIG_SETMASK, [], NULL, 8) = 0
[pid 649417] --- SIGCHLD {si_signo=SIGCHLD, si_code=CLD_EXITED, si_pid=649418, si_uid=1006, si_status=0, si_utime=0, si_stime=0} ---
[pid 649417] wait4(-1, 0x7fffb1f38050, WNOHANG, NULL) = -1 ECHILD (No child processes)
[pid 649417] rt_sigreturn({mask=[]})    = 0
[pid 649417] rt_sigprocmask(SIG_BLOCK, NULL, [], 8) = 0
[pid 649417] rt_sigprocmask(SIG_BLOCK, [INT TERM CHLD], [], 8) = 0
[pid 649417] clone(child_stack=NULL, flags=CLONE_CHILD_CLEARTID|CLONE_CHILD_SETTID|SIGCHLD, child_tidptr=0x7f584c4b0a10) = 649682
strace: Process 649682 attached
[pid 649417] rt_sigprocmask(SIG_SETMASK, [], NULL, 8) = 0
[pid 649682] set_robust_list(0x7f584c4b0a20, 24) = 0
[pid 649417] rt_sigprocmask(SIG_BLOCK, [CHLD], [], 8) = 0
[pid 649682] getpid( <unfinished ...>
[pid 649417] rt_sigprocmask(SIG_SETMASK, [],  <unfinished ...>
[pid 649682] <... getpid resumed>)      = 649682
[pid 649417] <... rt_sigprocmask resumed>NULL, 8) = 0
[pid 649682] rt_sigprocmask(SIG_SETMASK, [],  <unfinished ...>
[pid 649417] rt_sigprocmask(SIG_BLOCK, [CHLD],  <unfinished ...>
[pid 649682] <... rt_sigprocmask resumed>NULL, 8) = 0
[pid 649417] <... rt_sigprocmask resumed>[], 8) = 0
[pid 649682] rt_sigaction(SIGTSTP, {sa_handler=SIG_DFL, sa_mask=[], sa_flags=SA_RESTORER, sa_restorer=0x7f584c242520},  <unfinished ...>
[pid 649417] rt_sigaction(SIGINT, {sa_handler=0x5577b9578dc0, sa_mask=[], sa_flags=SA_RESTORER, sa_restorer=0x7f584c242520},  <unfinished ...>
[pid 649682] <... rt_sigaction resumed>{sa_handler=SIG_DFL, sa_mask=[], sa_flags=SA_RESTORER, sa_restorer=0x7f584c242520}, 8) = 0
[pid 649417] <... rt_sigaction resumed>{sa_handler=0x5577b95a3410, sa_mask=[], sa_flags=SA_RESTORER, sa_restorer=0x7f584c242520}, 8) = 0
[pid 649682] rt_sigaction(SIGTTIN, {sa_handler=SIG_DFL, sa_mask=[], sa_flags=SA_RESTORER, sa_restorer=0x7f584c242520},  <unfinished ...>
[pid 649417] wait4(-1,  <unfinished ...>
[pid 649682] <... rt_sigaction resumed>{sa_handler=SIG_DFL, sa_mask=[], sa_flags=SA_RESTORER, sa_restorer=0x7f584c242520}, 8) = 0
[pid 649682] rt_sigaction(SIGTTOU, {sa_handler=SIG_DFL, sa_mask=[], sa_flags=SA_RESTORER, sa_restorer=0x7f584c242520}, {sa_handler=SIG_DFL, sa_mask=[], sa_flags=SA_RESTORER, sa_restorer=0x7f584c242520}, 8) = 0
[pid 649682] rt_sigaction(SIGINT, {sa_handler=SIG_DFL, sa_mask=[], sa_flags=SA_RESTORER, sa_restorer=0x7f584c242520}, {sa_handler=0x5577b95a3410, sa_mask=[], sa_flags=SA_RESTORER, sa_restorer=0x7f584c242520}, 8) = 0
[pid 649682] rt_sigaction(SIGQUIT, {sa_handler=SIG_DFL, sa_mask=[], sa_flags=SA_RESTORER, sa_restorer=0x7f584c242520}, {sa_handler=SIG_DFL, sa_mask=[], sa_flags=SA_RESTORER, sa_restorer=0x7f584c242520}, 8) = 0
[pid 649682] rt_sigaction(SIGCHLD, {sa_handler=SIG_DFL, sa_mask=[], sa_flags=SA_RESTORER|SA_RESTART, sa_restorer=0x7f584c242520}, {sa_handler=0x5577b9576d10, sa_mask=[], sa_flags=SA_RESTORER|SA_RESTART, sa_restorer=0x7f584c242520}, 8) = 0
[pid 649682] execve("/usr/bin/sleep", ["sleep", "10"], 0x5577b9e20b60 /* 54 vars */) = 0
[pid 649682] brk(NULL)                  = 0x5591174fc000
[pid 649682] arch_prctl(0x3001 /* ARCH_??? */, 0x7fffce0decd0) = -1 EINVAL (Invalid argument)
[pid 649682] mmap(NULL, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f6113dd6000
[pid 649682] access("/etc/ld.so.preload", R_OK) = -1 ENOENT (No such file or directory)
[pid 649682] openat(AT_FDCWD, "/etc/ld.so.cache", O_RDONLY|O_CLOEXEC) = 3
[pid 649682] newfstatat(3, "", {st_mode=S_IFREG|0644, st_size=95179, ...}, AT_EMPTY_PATH) = 0
[pid 649682] mmap(NULL, 95179, PROT_READ, MAP_PRIVATE, 3, 0) = 0x7f6113dbe000
[pid 649682] close(3)                   = 0
[pid 649682] openat(AT_FDCWD, "/lib/x86_64-linux-gnu/libc.so.6", O_RDONLY|O_CLOEXEC) = 3
[pid 649682] read(3, "\177ELF\2\1\1\3\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0P\237\2\0\0\0\0\0"..., 832) = 832
[pid 649682] pread64(3, "\6\0\0\0\4\0\0\0@\0\0\0\0\0\0\0@\0\0\0\0\0\0\0@\0\0\0\0\0\0\0"..., 784, 64) = 784
[pid 649682] pread64(3, "\4\0\0\0 \0\0\0\5\0\0\0GNU\0\2\0\0\300\4\0\0\0\3\0\0\0\0\0\0\0"..., 48, 848) = 48
[pid 649682] pread64(3, "\4\0\0\0\24\0\0\0\3\0\0\0GNU\0\302\211\332Pq\2439\235\350\223\322\257\201\326\243\f"..., 68, 896) = 68
[pid 649682] newfstatat(3, "", {st_mode=S_IFREG|0755, st_size=2220400, ...}, AT_EMPTY_PATH) = 0
[pid 649682] pread64(3, "\6\0\0\0\4\0\0\0@\0\0\0\0\0\0\0@\0\0\0\0\0\0\0@\0\0\0\0\0\0\0"..., 784, 64) = 784
[pid 649682] mmap(NULL, 2264656, PROT_READ, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x7f6113a00000
[pid 649682] mprotect(0x7f6113a28000, 2023424, PROT_NONE) = 0
[pid 649682] mmap(0x7f6113a28000, 1658880, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x28000) = 0x7f6113a28000
[pid 649682] mmap(0x7f6113bbd000, 360448, PROT_READ, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x1bd000) = 0x7f6113bbd000
[pid 649682] mmap(0x7f6113c16000, 24576, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x215000) = 0x7f6113c16000
[pid 649682] mmap(0x7f6113c1c000, 52816, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0x7f6113c1c000
[pid 649682] close(3)                   = 0
[pid 649682] mmap(NULL, 12288, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f6113dbb000
[pid 649682] arch_prctl(ARCH_SET_FS, 0x7f6113dbb740) = 0
[pid 649682] set_tid_address(0x7f6113dbba10) = 649682
[pid 649682] set_robust_list(0x7f6113dbba20, 24) = 0
[pid 649682] rseq(0x7f6113dbc0e0, 0x20, 0, 0x53053053) = 0
[pid 649682] mprotect(0x7f6113c16000, 16384, PROT_READ) = 0
[pid 649682] mprotect(0x5591162b5000, 4096, PROT_READ) = 0
[pid 649682] mprotect(0x7f6113e10000, 8192, PROT_READ) = 0
[pid 649682] prlimit64(0, RLIMIT_STACK, NULL, {rlim_cur=8192*1024, rlim_max=RLIM64_INFINITY}) = 0
[pid 649682] munmap(0x7f6113dbe000, 95179) = 0
[pid 649682] getrandom("\x76\xed\x66\x62\x5c\xcf\x79\x1b", 8, GRND_NONBLOCK) = 8
[pid 649682] brk(NULL)                  = 0x5591174fc000
[pid 649682] brk(0x55911751d000)        = 0x55911751d000
[pid 649682] openat(AT_FDCWD, "/usr/lib/locale/locale-archive", O_RDONLY|O_CLOEXEC) = 3
[pid 649682] newfstatat(3, "", {st_mode=S_IFREG|0644, st_size=8872448, ...}, AT_EMPTY_PATH) = 0
[pid 649682] mmap(NULL, 8872448, PROT_READ, MAP_PRIVATE, 3, 0) = 0x7f6113000000
[pid 649682] close(3)                   = 0
[pid 649682] clock_nanosleep(CLOCK_REALTIME, 0, {tv_sec=10, tv_nsec=0}, 0x7fffce0ded20) = 0
[pid 649682] close(1)                   = 0
[pid 649682] close(2)                   = 0
[pid 649682] exit_group(0)              = ?
[pid 649682] +++ exited with 0 +++
[pid 649417] <... wait4 resumed>[{WIFEXITED(s) && WEXITSTATUS(s) == 0}], 0, NULL) = 649682
[pid 649417] rt_sigaction(SIGINT, {sa_handler=0x5577b95a3410, sa_mask=[], sa_flags=SA_RESTORER, sa_restorer=0x7f584c242520}, {sa_handler=0x5577b9578dc0, sa_mask=[], sa_flags=SA_RESTORER, sa_restorer=0x7f584c242520}, 8) = 0
[pid 649417] rt_sigprocmask(SIG_SETMASK, [], NULL, 8) = 0
[pid 649417] --- SIGCHLD {si_signo=SIGCHLD, si_code=CLD_EXITED, si_pid=649682, si_uid=1006, si_status=0, si_utime=0, si_stime=0} ---
[pid 649417] wait4(-1, 0x7fffb1f38090, WNOHANG, NULL) = -1 ECHILD (No child processes)
[pid 649417] rt_sigreturn({mask=[]})    = 0
[pid 649417] exit_group(0)              = ?
[pid 649417] +++ exited with 0 +++
<... wait4 resumed>[{WIFEXITED(s) && WEXITSTATUS(s) == 0}], 0, NULL) = 649417
rt_sigaction(SIGINT, {sa_handler=SIG_DFL, sa_mask=[], sa_flags=SA_RESTORER, sa_restorer=0x7f584c242520}, {sa_handler=0x5577b9578dc0, sa_mask=[], sa_flags=SA_RESTORER, sa_restorer=0x7f584c242520}, 8) = 0
ioctl(2, TIOCGWINSZ, {ws_row=21, ws_col=200, ws_xpixel=0, ws_ypixel=0}) = 0
ioctl(1, TCGETS, {B38400 opost isig icanon echo ...}) = 0
getuid()                                = 1006
geteuid()                               = 1006
getgid()                                = 1002
getegid()                               = 1002
getuid()                                = 1006
geteuid()                               = 1006
getgid()                                = 1002
getegid()                               = 1002
newfstatat(AT_FDCWD, "/home/zhangchen/.terminfo", 0x5577b9e26460, 0) = -1 ENOENT (No such file or directory)
newfstatat(AT_FDCWD, "/etc/terminfo", {st_mode=S_IFDIR|0755, st_size=4096, ...}, 0) = 0
newfstatat(AT_FDCWD, "/lib/terminfo", {st_mode=S_IFDIR|0755, st_size=4096, ...}, 0) = 0
newfstatat(AT_FDCWD, "/usr/share/terminfo", {st_mode=S_IFDIR|0755, st_size=4096, ...}, 0) = 0
access("/etc/terminfo/x/xterm-256color", R_OK) = -1 ENOENT (No such file or directory)
access("/lib/terminfo/x/xterm-256color", R_OK) = 0
openat(AT_FDCWD, "/lib/terminfo/x/xterm-256color", O_RDONLY) = 3
newfstatat(3, "", {st_mode=S_IFREG|0644, st_size=3852, ...}, AT_EMPTY_PATH) = 0
read(3, "\36\2%\0&\0\17\0\235\1Z\6xterm-256color|xterm"..., 32768) = 3852
read(3, "", 28672)                      = 0
close(3)                                = 0
ioctl(1, TCGETS, {B38400 opost isig icanon echo ...}) = 0
ioctl(1, TCGETS, {B38400 opost isig icanon echo ...}) = 0
ioctl(1, TCGETS, {B38400 opost isig icanon echo ...}) = 0
ioctl(1, TCGETS, {B38400 opost isig icanon echo ...}) = 0
ioctl(1, TIOCGWINSZ, {ws_row=21, ws_col=200, ws_xpixel=0, ws_ypixel=0}) = 0
ioctl(0, TIOCGWINSZ, {ws_row=21, ws_col=200, ws_xpixel=0, ws_ypixel=0}) = 0
brk(0x5577b9e51000)                     = 0x5577b9e51000
rt_sigprocmask(SIG_SETMASK, [], NULL, 8) = 0
--- SIGCHLD {si_signo=SIGCHLD, si_code=CLD_EXITED, si_pid=649417, si_uid=1006, si_status=0, si_utime=0, si_stime=0} ---
wait4(-1, 0x7fffb1f38310, WNOHANG, NULL) = -1 ECHILD (No child processes)
rt_sigreturn({mask=[]})                 = 0
read(255, "", 20)                       = 0
rt_sigprocmask(SIG_BLOCK, [CHLD], [], 8) = 0
rt_sigprocmask(SIG_SETMASK, [], NULL, 8) = 0
exit_group(0)                           = ?
+++ exited with 0 +++

       像之前一样,首先strace进程创建子进程后调用execve进行替换(替换为bash)。从其中的getpid()=649416可以看出,该bash进程的PID为649416。从getppid()=649413可以看出,该bash进程父进程的PID为649413,这是strace进程的PID,而strace进程的父进程是终端内运行的bash。

        其中共存在三个clone,其中的第一个clone(****)=649417,展现了bash进程在读取到了小括号后,创建了一个子shell,并且子shell的PID为649417。但是在这之后并没有执行execve进行替换(如果是执行了脚本中的bash命令,则会首先clone并使用execve进行替换,注意这两者的区别)。

        第二个出现的clone是[pid 649417] clone(****)=649418,这表示子shell又创建了一个子进程,并且子进程的PID为649418。后面的[pid 649418] execve("/usr/bin/sleep", ["sleep", "20"], 0x5577b9e20b60 /* 54 vars */)=0展示了该子进程进行替换的过程。上面的两步,导致子shell进程创建了一个sleep子进程。

        第三个出现的clone是[pid 649417] clone(****)=649682,这表示子shell创建了第二个子进程,并且子进程的PID为649682。后面的[pid 649682] execve("/usr/bin/sleep", ["sleep", "10"], 0x5577b9e20b60 /* 54 vars */)=0展示了该子进程进行替换的过程。上面的两步,导致子shell进程创建了第二个sleep子进程。

        在运行strace命令时,我们可以在另一个终端利用ps命令观察到进程的创建情况,如下所示。注意其中的,sleep 10进程需要在sleep 20进程结束后才能观察到。

UID          PID    PPID  C STIME TTY          TIME CMD
zhangch+  649413  645887  0 13:31 pts/15   00:00:00 strace -f bash test.sh
zhangch+  649416  649413  0 13:31 pts/15   00:00:00 bash test.sh
zhangch+  649417  649416  0 13:31 pts/15   00:00:00 bash test.sh
zhangch+  649418  649417  0 13:31 pts/15   00:00:00 sleep 20
UID          PID    PPID  C STIME TTY          TIME CMD
zhangch+  649413  645887  0 13:31 pts/15   00:00:00 strace -f bash test.sh
zhangch+  649416  649413  0 13:31 pts/15   00:00:00 bash test.sh
zhangch+  649417  649416  0 13:31 pts/15   00:00:00 bash test.sh
zhangch+  649682  649417  0 13:32 pts/15   00:00:00 sleep 10

        可以从图中看出PID为649417的进程就是创建的子shell,这印证了我们的说法。

        下面我们尝试在小括号中只放一条命令,并观察结果。

​# 文件test.sh(sleep 20)

        此时使用strace追踪的结果如下所示。

execve("/usr/bin/bash", ["bash", "test.sh"], 0x7fff4735b310 /* 55 vars */) = 0
brk(NULL)                               = 0x55611d9ff000
arch_prctl(0x3001 /* ARCH_??? */, 0x7fff55dc2db0) = -1 EINVAL (Invalid argument)
mmap(NULL, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fd7fcc46000
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
newfstatat(3, "", {st_mode=S_IFREG|0644, st_size=95179, ...}, AT_EMPTY_PATH) = 0
mmap(NULL, 95179, PROT_READ, MAP_PRIVATE, 3, 0) = 0x7fd7fcc2e000
close(3)                                = 0
openat(AT_FDCWD, "/lib/x86_64-linux-gnu/libtinfo.so.6", 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\0"..., 832) = 832
newfstatat(3, "", {st_mode=S_IFREG|0644, st_size=200136, ...}, AT_EMPTY_PATH) = 0
mmap(NULL, 203040, PROT_READ, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x7fd7fcbfc000
mmap(0x7fd7fcc0a000, 69632, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0xe000) = 0x7fd7fcc0a000
mmap(0x7fd7fcc1b000, 57344, PROT_READ, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x1f000) = 0x7fd7fcc1b000
mmap(0x7fd7fcc29000, 20480, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x2c000) = 0x7fd7fcc29000
close(3)                                = 0
openat(AT_FDCWD, "/lib/x86_64-linux-gnu/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\0P\237\2\0\0\0\0\0"..., 832) = 832
pread64(3, "\6\0\0\0\4\0\0\0@\0\0\0\0\0\0\0@\0\0\0\0\0\0\0@\0\0\0\0\0\0\0"..., 784, 64) = 784
pread64(3, "\4\0\0\0 \0\0\0\5\0\0\0GNU\0\2\0\0\300\4\0\0\0\3\0\0\0\0\0\0\0"..., 48, 848) = 48
pread64(3, "\4\0\0\0\24\0\0\0\3\0\0\0GNU\0\302\211\332Pq\2439\235\350\223\322\257\201\326\243\f"..., 68, 896) = 68
newfstatat(3, "", {st_mode=S_IFREG|0755, st_size=2220400, ...}, AT_EMPTY_PATH) = 0
pread64(3, "\6\0\0\0\4\0\0\0@\0\0\0\0\0\0\0@\0\0\0\0\0\0\0@\0\0\0\0\0\0\0"..., 784, 64) = 784
mmap(NULL, 2264656, PROT_READ, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x7fd7fc800000
mprotect(0x7fd7fc828000, 2023424, PROT_NONE) = 0
mmap(0x7fd7fc828000, 1658880, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x28000) = 0x7fd7fc828000
mmap(0x7fd7fc9bd000, 360448, PROT_READ, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x1bd000) = 0x7fd7fc9bd000
mmap(0x7fd7fca16000, 24576, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x215000) = 0x7fd7fca16000
mmap(0x7fd7fca1c000, 52816, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0x7fd7fca1c000
close(3)                                = 0
mmap(NULL, 12288, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fd7fcbf9000
arch_prctl(ARCH_SET_FS, 0x7fd7fcbf9740) = 0
set_tid_address(0x7fd7fcbf9a10)         = 661035
set_robust_list(0x7fd7fcbf9a20, 24)     = 0
rseq(0x7fd7fcbfa0e0, 0x20, 0, 0x53053053) = 0
mprotect(0x7fd7fca16000, 16384, PROT_READ) = 0
mprotect(0x7fd7fcc29000, 16384, PROT_READ) = 0
mprotect(0x55611c4a1000, 16384, PROT_READ) = 0
mprotect(0x7fd7fcc80000, 8192, PROT_READ) = 0
prlimit64(0, RLIMIT_STACK, NULL, {rlim_cur=8192*1024, rlim_max=RLIM64_INFINITY}) = 0
munmap(0x7fd7fcc2e000, 95179)           = 0
openat(AT_FDCWD, "/dev/tty", O_RDWR|O_NONBLOCK) = 3
close(3)                                = 0
getrandom("\x1b\x51\x8d\x2a\xb7\x02\xc5\xd7", 8, GRND_NONBLOCK) = 8
brk(NULL)                               = 0x55611d9ff000
brk(0x55611da20000)                     = 0x55611da20000
openat(AT_FDCWD, "/usr/lib/locale/locale-archive", O_RDONLY|O_CLOEXEC) = 3
newfstatat(3, "", {st_mode=S_IFREG|0644, st_size=8872448, ...}, AT_EMPTY_PATH) = 0
mmap(NULL, 8872448, PROT_READ, MAP_PRIVATE, 3, 0) = 0x7fd7fbe00000
close(3)                                = 0
openat(AT_FDCWD, "/usr/lib/x86_64-linux-gnu/gconv/gconv-modules.cache", O_RDONLY) = 3
newfstatat(3, "", {st_mode=S_IFREG|0644, st_size=27002, ...}, AT_EMPTY_PATH) = 0
mmap(NULL, 27002, PROT_READ, MAP_SHARED, 3, 0) = 0x7fd7fcc3f000
close(3)                                = 0
futex(0x7fd7fca1ba6c, FUTEX_WAKE_PRIVATE, 2147483647) = 0
getuid()                                = 1006
getgid()                                = 1002
geteuid()                               = 1006
getegid()                               = 1002
rt_sigprocmask(SIG_BLOCK, NULL, [], 8)  = 0
ioctl(-1, TIOCGPGRP, 0x7fff55dc2ca4)    = -1 EBADF (Bad file descriptor)
sysinfo({uptime=7262941, loads=[34464, 38112, 38752], totalram=135030112256, freeram=18682093568, sharedram=3393511424, bufferram=2823491584, totalswap=31999389696, freeswap=16653172736, procs=4084, totalhigh=0, freehigh=0, mem_unit=1}) = 0
rt_sigaction(SIGCHLD, {sa_handler=SIG_DFL, sa_mask=[], sa_flags=SA_RESTORER|SA_RESTART, sa_restorer=0x7fd7fc842520}, {sa_handler=SIG_DFL, sa_mask=[], sa_flags=0}, 8) = 0
rt_sigaction(SIGCHLD, {sa_handler=SIG_DFL, sa_mask=[], sa_flags=SA_RESTORER|SA_RESTART, sa_restorer=0x7fd7fc842520}, {sa_handler=SIG_DFL, sa_mask=[], sa_flags=SA_RESTORER|SA_RESTART, sa_restorer=0x7fd7fc842520}, 8) = 0
rt_sigaction(SIGINT, {sa_handler=SIG_DFL, sa_mask=[], sa_flags=SA_RESTORER, sa_restorer=0x7fd7fc842520}, {sa_handler=SIG_DFL, sa_mask=[], sa_flags=0}, 8) = 0
rt_sigaction(SIGINT, {sa_handler=SIG_DFL, sa_mask=[], sa_flags=SA_RESTORER, sa_restorer=0x7fd7fc842520}, {sa_handler=SIG_DFL, sa_mask=[], sa_flags=SA_RESTORER, sa_restorer=0x7fd7fc842520}, 8) = 0
rt_sigaction(SIGQUIT, {sa_handler=SIG_DFL, sa_mask=[], sa_flags=SA_RESTORER, sa_restorer=0x7fd7fc842520}, {sa_handler=SIG_DFL, sa_mask=[], sa_flags=0}, 8) = 0
rt_sigaction(SIGQUIT, {sa_handler=SIG_DFL, sa_mask=[], sa_flags=SA_RESTORER, sa_restorer=0x7fd7fc842520}, {sa_handler=SIG_DFL, sa_mask=[], sa_flags=SA_RESTORER, sa_restorer=0x7fd7fc842520}, 8) = 0
rt_sigaction(SIGTSTP, {sa_handler=SIG_DFL, sa_mask=[], sa_flags=SA_RESTORER, sa_restorer=0x7fd7fc842520}, {sa_handler=SIG_DFL, sa_mask=[], sa_flags=0}, 8) = 0
rt_sigaction(SIGTSTP, {sa_handler=SIG_DFL, sa_mask=[], sa_flags=SA_RESTORER, sa_restorer=0x7fd7fc842520}, {sa_handler=SIG_DFL, sa_mask=[], sa_flags=SA_RESTORER, sa_restorer=0x7fd7fc842520}, 8) = 0
rt_sigaction(SIGTTIN, {sa_handler=SIG_DFL, sa_mask=[], sa_flags=SA_RESTORER, sa_restorer=0x7fd7fc842520}, {sa_handler=SIG_DFL, sa_mask=[], sa_flags=0}, 8) = 0
rt_sigaction(SIGTTIN, {sa_handler=SIG_DFL, sa_mask=[], sa_flags=SA_RESTORER, sa_restorer=0x7fd7fc842520}, {sa_handler=SIG_DFL, sa_mask=[], sa_flags=SA_RESTORER, sa_restorer=0x7fd7fc842520}, 8) = 0
rt_sigaction(SIGTTOU, {sa_handler=SIG_DFL, sa_mask=[], sa_flags=SA_RESTORER, sa_restorer=0x7fd7fc842520}, {sa_handler=SIG_DFL, sa_mask=[], sa_flags=0}, 8) = 0
rt_sigaction(SIGTTOU, {sa_handler=SIG_DFL, sa_mask=[], sa_flags=SA_RESTORER, sa_restorer=0x7fd7fc842520}, {sa_handler=SIG_DFL, sa_mask=[], sa_flags=SA_RESTORER, sa_restorer=0x7fd7fc842520}, 8) = 0
rt_sigprocmask(SIG_BLOCK, NULL, [], 8)  = 0
rt_sigaction(SIGQUIT, {sa_handler=SIG_IGN, sa_mask=[], sa_flags=SA_RESTORER, sa_restorer=0x7fd7fc842520}, {sa_handler=SIG_DFL, sa_mask=[], sa_flags=SA_RESTORER, sa_restorer=0x7fd7fc842520}, 8) = 0
uname({sysname="Linux", nodename="liubo-SYS-7048GR-TR", ...}) = 0
newfstatat(AT_FDCWD, "/home/zhangchen", {st_mode=S_IFDIR|0750, st_size=4096, ...}, 0) = 0
newfstatat(AT_FDCWD, ".", {st_mode=S_IFDIR|0750, st_size=4096, ...}, 0) = 0
newfstatat(AT_FDCWD, "/home", {st_mode=S_IFDIR|0755, st_size=4096, ...}, 0) = 0
newfstatat(AT_FDCWD, "/home/zhangchen", {st_mode=S_IFDIR|0750, st_size=4096, ...}, 0) = 0
getpid()                                = 661035
getppid()                               = 661032
newfstatat(AT_FDCWD, ".", {st_mode=S_IFDIR|0750, st_size=4096, ...}, 0) = 0
newfstatat(AT_FDCWD, "/home/zhangchen/.vscode-server/cli/servers/Stable-dc96b837cf6bb4af9cd736aa3af08cf8279f7685/server/bin/remote-cli/bash", 0x7fff55dc28e0, 0) = -1 ENOENT (No such file or directory)
newfstatat(AT_FDCWD, "/home/zhangchen/.conda/envs/DL/bin/bash", 0x7fff55dc28e0, 0) = -1 ENOENT (No such file or directory)
newfstatat(AT_FDCWD, "/opt/miniconda3/condabin/bash", 0x7fff55dc28e0, 0) = -1 ENOENT (No such file or directory)
newfstatat(AT_FDCWD, "/opt/miniconda3/bin/bash", 0x7fff55dc28e0, 0) = -1 ENOENT (No such file or directory)
newfstatat(AT_FDCWD, "/usr/local/sbin/bash", 0x7fff55dc28e0, 0) = -1 ENOENT (No such file or directory)
newfstatat(AT_FDCWD, "/usr/local/bin/bash", 0x7fff55dc28e0, 0) = -1 ENOENT (No such file or directory)
newfstatat(AT_FDCWD, "/usr/sbin/bash", 0x7fff55dc28e0, 0) = -1 ENOENT (No such file or directory)
newfstatat(AT_FDCWD, "/usr/bin/bash", {st_mode=S_IFREG|0755, st_size=1396520, ...}, 0) = 0
newfstatat(AT_FDCWD, "/usr/bin/bash", {st_mode=S_IFREG|0755, st_size=1396520, ...}, 0) = 0
geteuid()                               = 1006
getegid()                               = 1002
getuid()                                = 1006
getgid()                                = 1002
access("/usr/bin/bash", X_OK)           = 0
newfstatat(AT_FDCWD, "/usr/bin/bash", {st_mode=S_IFREG|0755, st_size=1396520, ...}, 0) = 0
geteuid()                               = 1006
getegid()                               = 1002
getuid()                                = 1006
getgid()                                = 1002
access("/usr/bin/bash", R_OK)           = 0
newfstatat(AT_FDCWD, "/usr/bin/bash", {st_mode=S_IFREG|0755, st_size=1396520, ...}, 0) = 0
newfstatat(AT_FDCWD, "/usr/bin/bash", {st_mode=S_IFREG|0755, st_size=1396520, ...}, 0) = 0
geteuid()                               = 1006
getegid()                               = 1002
getuid()                                = 1006
getgid()                                = 1002
access("/usr/bin/bash", X_OK)           = 0
newfstatat(AT_FDCWD, "/usr/bin/bash", {st_mode=S_IFREG|0755, st_size=1396520, ...}, 0) = 0
geteuid()                               = 1006
getegid()                               = 1002
getuid()                                = 1006
getgid()                                = 1002
access("/usr/bin/bash", R_OK)           = 0
getpid()                                = 661035
getppid()                               = 661032
getpid()                                = 661035
getppid()                               = 661032
getpgrp()                               = 661032
ioctl(2, TIOCGPGRP, [661032])           = 0
rt_sigaction(SIGCHLD, {sa_handler=0x55611c3b6d10, sa_mask=[], sa_flags=SA_RESTORER|SA_RESTART, sa_restorer=0x7fd7fc842520}, {sa_handler=SIG_DFL, sa_mask=[], sa_flags=SA_RESTORER|SA_RESTART, sa_restorer=0x7fd7fc842520}, 8) = 0
prlimit64(0, RLIMIT_NPROC, NULL, {rlim_cur=514857, rlim_max=514857}) = 0
rt_sigprocmask(SIG_BLOCK, NULL, [], 8)  = 0
openat(AT_FDCWD, "test.sh", O_RDONLY)   = 3
newfstatat(AT_FDCWD, "test.sh", {st_mode=S_IFREG|0777, st_size=11, ...}, 0) = 0
ioctl(3, TCGETS, 0x7fff55dc2c40)        = -1 ENOTTY (Inappropriate ioctl for device)
lseek(3, 0, SEEK_CUR)                   = 0
read(3, "(sleep 20)\n", 80)             = 11
lseek(3, 0, SEEK_SET)                   = 0
prlimit64(0, RLIMIT_NOFILE, NULL, {rlim_cur=1024*1024, rlim_max=1024*1024}) = 0
fcntl(255, F_GETFD)                     = -1 EBADF (Bad file descriptor)
dup2(3, 255)                            = 255
close(3)                                = 0
fcntl(255, F_SETFD, FD_CLOEXEC)         = 0
fcntl(255, F_GETFL)                     = 0x8000 (flags O_RDONLY|O_LARGEFILE)
newfstatat(255, "", {st_mode=S_IFREG|0777, st_size=11, ...}, AT_EMPTY_PATH) = 0
lseek(255, 0, SEEK_CUR)                 = 0
read(255, "(sleep 20)\n", 11)           = 11
rt_sigprocmask(SIG_BLOCK, NULL, [], 8)  = 0
rt_sigprocmask(SIG_BLOCK, [INT TERM CHLD], [], 8) = 0
clone(child_stack=NULL, flags=CLONE_CHILD_CLEARTID|CLONE_CHILD_SETTID|SIGCHLD, child_tidptr=0x7fd7fcbf9a10) = 661036
strace: Process 661036 attached
[pid 661035] rt_sigprocmask(SIG_SETMASK, [], NULL, 8) = 0
[pid 661035] rt_sigprocmask(SIG_BLOCK, [CHLD], [], 8) = 0
[pid 661036] set_robust_list(0x7fd7fcbf9a20, 24 <unfinished ...>
[pid 661035] rt_sigprocmask(SIG_SETMASK, [],  <unfinished ...>
[pid 661036] <... set_robust_list resumed>) = 0
[pid 661035] <... rt_sigprocmask resumed>NULL, 8) = 0
[pid 661035] rt_sigprocmask(SIG_BLOCK, [CHLD], [], 8) = 0
[pid 661036] getpid( <unfinished ...>
[pid 661035] rt_sigaction(SIGINT, {sa_handler=0x55611c3b8dc0, sa_mask=[], sa_flags=SA_RESTORER, sa_restorer=0x7fd7fc842520},  <unfinished ...>
[pid 661036] <... getpid resumed>)      = 661036
[pid 661035] <... rt_sigaction resumed>{sa_handler=SIG_DFL, sa_mask=[], sa_flags=SA_RESTORER, sa_restorer=0x7fd7fc842520}, 8) = 0
[pid 661035] wait4(-1,  <unfinished ...>
[pid 661036] close(255)                 = 0
[pid 661036] rt_sigprocmask(SIG_SETMASK, [], NULL, 8) = 0
[pid 661036] rt_sigaction(SIGTSTP, {sa_handler=SIG_DFL, sa_mask=[], sa_flags=SA_RESTORER, sa_restorer=0x7fd7fc842520}, {sa_handler=SIG_DFL, sa_mask=[], sa_flags=SA_RESTORER, sa_restorer=0x7fd7fc842520}, 8) = 0
[pid 661036] rt_sigaction(SIGTTIN, {sa_handler=SIG_DFL, sa_mask=[], sa_flags=SA_RESTORER, sa_restorer=0x7fd7fc842520}, {sa_handler=SIG_DFL, sa_mask=[], sa_flags=SA_RESTORER, sa_restorer=0x7fd7fc842520}, 8) = 0
[pid 661036] rt_sigaction(SIGTTOU, {sa_handler=SIG_DFL, sa_mask=[], sa_flags=SA_RESTORER, sa_restorer=0x7fd7fc842520}, {sa_handler=SIG_DFL, sa_mask=[], sa_flags=SA_RESTORER, sa_restorer=0x7fd7fc842520}, 8) = 0
[pid 661036] rt_sigaction(SIGINT, {sa_handler=SIG_DFL, sa_mask=[], sa_flags=SA_RESTORER, sa_restorer=0x7fd7fc842520}, {sa_handler=SIG_DFL, sa_mask=[], sa_flags=SA_RESTORER, sa_restorer=0x7fd7fc842520}, 8) = 0
[pid 661036] rt_sigaction(SIGQUIT, {sa_handler=SIG_DFL, sa_mask=[], sa_flags=SA_RESTORER, sa_restorer=0x7fd7fc842520}, {sa_handler=SIG_IGN, sa_mask=[], sa_flags=SA_RESTORER, sa_restorer=0x7fd7fc842520}, 8) = 0
[pid 661036] rt_sigaction(SIGCHLD, {sa_handler=SIG_DFL, sa_mask=[], sa_flags=SA_RESTORER|SA_RESTART, sa_restorer=0x7fd7fc842520}, {sa_handler=0x55611c3b6d10, sa_mask=[], sa_flags=SA_RESTORER|SA_RESTART, sa_restorer=0x7fd7fc842520}, 8) = 0
[pid 661036] rt_sigaction(SIGINT, {sa_handler=0x55611c3e3410, sa_mask=[], sa_flags=SA_RESTORER, sa_restorer=0x7fd7fc842520}, {sa_handler=SIG_DFL, sa_mask=[], sa_flags=SA_RESTORER, sa_restorer=0x7fd7fc842520}, 8) = 0
[pid 661036] rt_sigaction(SIGCHLD, {sa_handler=0x55611c3b6d10, sa_mask=[], sa_flags=SA_RESTORER|SA_RESTART, sa_restorer=0x7fd7fc842520}, {sa_handler=SIG_DFL, sa_mask=[], sa_flags=SA_RESTORER|SA_RESTART, sa_restorer=0x7fd7fc842520}, 8) = 0
[pid 661036] rt_sigprocmask(SIG_BLOCK, [CHLD], [], 8) = 0
[pid 661036] rt_sigprocmask(SIG_SETMASK, [], NULL, 8) = 0
[pid 661036] newfstatat(AT_FDCWD, ".", {st_mode=S_IFDIR|0750, st_size=4096, ...}, 0) = 0
[pid 661036] newfstatat(AT_FDCWD, "/home/zhangchen/.vscode-server/cli/servers/Stable-dc96b837cf6bb4af9cd736aa3af08cf8279f7685/server/bin/remote-cli/sleep", 0x7fff55dc25c0, 0) = -1 ENOENT (No such file or directory)
[pid 661036] newfstatat(AT_FDCWD, "/home/zhangchen/.conda/envs/DL/bin/sleep", 0x7fff55dc25c0, 0) = -1 ENOENT (No such file or directory)
[pid 661036] newfstatat(AT_FDCWD, "/opt/miniconda3/condabin/sleep", 0x7fff55dc25c0, 0) = -1 ENOENT (No such file or directory)
[pid 661036] newfstatat(AT_FDCWD, "/opt/miniconda3/bin/sleep", 0x7fff55dc25c0, 0) = -1 ENOENT (No such file or directory)
[pid 661036] newfstatat(AT_FDCWD, "/usr/local/sbin/sleep", 0x7fff55dc25c0, 0) = -1 ENOENT (No such file or directory)
[pid 661036] newfstatat(AT_FDCWD, "/usr/local/bin/sleep", 0x7fff55dc25c0, 0) = -1 ENOENT (No such file or directory)
[pid 661036] newfstatat(AT_FDCWD, "/usr/sbin/sleep", 0x7fff55dc25c0, 0) = -1 ENOENT (No such file or directory)
[pid 661036] newfstatat(AT_FDCWD, "/usr/bin/sleep", {st_mode=S_IFREG|0755, st_size=35328, ...}, 0) = 0
[pid 661036] newfstatat(AT_FDCWD, "/usr/bin/sleep", {st_mode=S_IFREG|0755, st_size=35328, ...}, 0) = 0
[pid 661036] geteuid()                  = 1006
[pid 661036] getegid()                  = 1002
[pid 661036] getuid()                   = 1006
[pid 661036] getgid()                   = 1002
[pid 661036] access("/usr/bin/sleep", X_OK) = 0
[pid 661036] newfstatat(AT_FDCWD, "/usr/bin/sleep", {st_mode=S_IFREG|0755, st_size=35328, ...}, 0) = 0
[pid 661036] geteuid()                  = 1006
[pid 661036] getegid()                  = 1002
[pid 661036] getuid()                   = 1006
[pid 661036] getgid()                   = 1002
[pid 661036] access("/usr/bin/sleep", R_OK) = 0
[pid 661036] newfstatat(AT_FDCWD, "/usr/bin/sleep", {st_mode=S_IFREG|0755, st_size=35328, ...}, 0) = 0
[pid 661036] newfstatat(AT_FDCWD, "/usr/bin/sleep", {st_mode=S_IFREG|0755, st_size=35328, ...}, 0) = 0
[pid 661036] geteuid()                  = 1006
[pid 661036] getegid()                  = 1002
[pid 661036] getuid()                   = 1006
[pid 661036] getgid()                   = 1002
[pid 661036] access("/usr/bin/sleep", X_OK) = 0
[pid 661036] newfstatat(AT_FDCWD, "/usr/bin/sleep", {st_mode=S_IFREG|0755, st_size=35328, ...}, 0) = 0
[pid 661036] geteuid()                  = 1006
[pid 661036] getegid()                  = 1002
[pid 661036] getuid()                   = 1006
[pid 661036] getgid()                   = 1002
[pid 661036] access("/usr/bin/sleep", R_OK) = 0
[pid 661036] rt_sigaction(SIGINT, {sa_handler=SIG_DFL, sa_mask=[], sa_flags=SA_RESTORER, sa_restorer=0x7fd7fc842520}, {sa_handler=0x55611c3e3410, sa_mask=[], sa_flags=SA_RESTORER, sa_restorer=0x7fd7fc842520}, 8) = 0
[pid 661036] rt_sigaction(SIGQUIT, {sa_handler=SIG_DFL, sa_mask=[], sa_flags=SA_RESTORER, sa_restorer=0x7fd7fc842520}, {sa_handler=SIG_DFL, sa_mask=[], sa_flags=SA_RESTORER, sa_restorer=0x7fd7fc842520}, 8) = 0
[pid 661036] rt_sigaction(SIGCHLD, {sa_handler=SIG_DFL, sa_mask=[], sa_flags=SA_RESTORER|SA_RESTART, sa_restorer=0x7fd7fc842520}, {sa_handler=0x55611c3b6d10, sa_mask=[], sa_flags=SA_RESTORER|SA_RESTART, sa_restorer=0x7fd7fc842520}, 8) = 0
[pid 661036] execve("/usr/bin/sleep", ["sleep", "20"], 0x55611da10b60 /* 54 vars */) = 0
[pid 661036] brk(NULL)                  = 0x55fbbd90b000
[pid 661036] arch_prctl(0x3001 /* ARCH_??? */, 0x7fff5bb3c790) = -1 EINVAL (Invalid argument)
[pid 661036] mmap(NULL, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f1c1af61000
[pid 661036] access("/etc/ld.so.preload", R_OK) = -1 ENOENT (No such file or directory)
[pid 661036] openat(AT_FDCWD, "/etc/ld.so.cache", O_RDONLY|O_CLOEXEC) = 3
[pid 661036] newfstatat(3, "", {st_mode=S_IFREG|0644, st_size=95179, ...}, AT_EMPTY_PATH) = 0
[pid 661036] mmap(NULL, 95179, PROT_READ, MAP_PRIVATE, 3, 0) = 0x7f1c1af49000
[pid 661036] close(3)                   = 0
[pid 661036] openat(AT_FDCWD, "/lib/x86_64-linux-gnu/libc.so.6", O_RDONLY|O_CLOEXEC) = 3
[pid 661036] read(3, "\177ELF\2\1\1\3\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0P\237\2\0\0\0\0\0"..., 832) = 832
[pid 661036] pread64(3, "\6\0\0\0\4\0\0\0@\0\0\0\0\0\0\0@\0\0\0\0\0\0\0@\0\0\0\0\0\0\0"..., 784, 64) = 784
[pid 661036] pread64(3, "\4\0\0\0 \0\0\0\5\0\0\0GNU\0\2\0\0\300\4\0\0\0\3\0\0\0\0\0\0\0"..., 48, 848) = 48
[pid 661036] pread64(3, "\4\0\0\0\24\0\0\0\3\0\0\0GNU\0\302\211\332Pq\2439\235\350\223\322\257\201\326\243\f"..., 68, 896) = 68
[pid 661036] newfstatat(3, "", {st_mode=S_IFREG|0755, st_size=2220400, ...}, AT_EMPTY_PATH) = 0
[pid 661036] pread64(3, "\6\0\0\0\4\0\0\0@\0\0\0\0\0\0\0@\0\0\0\0\0\0\0@\0\0\0\0\0\0\0"..., 784, 64) = 784
[pid 661036] mmap(NULL, 2264656, PROT_READ, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x7f1c1ac00000
[pid 661036] mprotect(0x7f1c1ac28000, 2023424, PROT_NONE) = 0
[pid 661036] mmap(0x7f1c1ac28000, 1658880, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x28000) = 0x7f1c1ac28000
[pid 661036] mmap(0x7f1c1adbd000, 360448, PROT_READ, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x1bd000) = 0x7f1c1adbd000
[pid 661036] mmap(0x7f1c1ae16000, 24576, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x215000) = 0x7f1c1ae16000
[pid 661036] mmap(0x7f1c1ae1c000, 52816, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0x7f1c1ae1c000
[pid 661036] close(3)                   = 0
[pid 661036] mmap(NULL, 12288, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f1c1af46000
[pid 661036] arch_prctl(ARCH_SET_FS, 0x7f1c1af46740) = 0
[pid 661036] set_tid_address(0x7f1c1af46a10) = 661036
[pid 661036] set_robust_list(0x7f1c1af46a20, 24) = 0
[pid 661036] rseq(0x7f1c1af470e0, 0x20, 0, 0x53053053) = 0
[pid 661036] mprotect(0x7f1c1ae16000, 16384, PROT_READ) = 0
[pid 661036] mprotect(0x55fbbc349000, 4096, PROT_READ) = 0
[pid 661036] mprotect(0x7f1c1af9b000, 8192, PROT_READ) = 0
[pid 661036] prlimit64(0, RLIMIT_STACK, NULL, {rlim_cur=8192*1024, rlim_max=RLIM64_INFINITY}) = 0
[pid 661036] munmap(0x7f1c1af49000, 95179) = 0
[pid 661036] getrandom("\x91\x51\x73\xc6\x31\xd4\xef\x2e", 8, GRND_NONBLOCK) = 8
[pid 661036] brk(NULL)                  = 0x55fbbd90b000
[pid 661036] brk(0x55fbbd92c000)        = 0x55fbbd92c000
[pid 661036] openat(AT_FDCWD, "/usr/lib/locale/locale-archive", O_RDONLY|O_CLOEXEC) = 3
[pid 661036] newfstatat(3, "", {st_mode=S_IFREG|0644, st_size=8872448, ...}, AT_EMPTY_PATH) = 0
[pid 661036] mmap(NULL, 8872448, PROT_READ, MAP_PRIVATE, 3, 0) = 0x7f1c1a200000
[pid 661036] close(3)                   = 0
[pid 661036] clock_nanosleep(CLOCK_REALTIME, 0, {tv_sec=20, tv_nsec=0}, 0x7fff5bb3c7e0) = 0
[pid 661036] close(1)                   = 0
[pid 661036] close(2)                   = 0
[pid 661036] exit_group(0)              = ?
[pid 661036] +++ exited with 0 +++
<... wait4 resumed>[{WIFEXITED(s) && WEXITSTATUS(s) == 0}], 0, NULL) = 661036
rt_sigaction(SIGINT, {sa_handler=SIG_DFL, sa_mask=[], sa_flags=SA_RESTORER, sa_restorer=0x7fd7fc842520}, {sa_handler=0x55611c3b8dc0, sa_mask=[], sa_flags=SA_RESTORER, sa_restorer=0x7fd7fc842520}, 8) = 0
ioctl(2, TIOCGWINSZ, {ws_row=21, ws_col=200, ws_xpixel=0, ws_ypixel=0}) = 0
ioctl(1, TCGETS, {B38400 opost isig icanon echo ...}) = 0
getuid()                                = 1006
geteuid()                               = 1006
getgid()                                = 1002
getegid()                               = 1002
getuid()                                = 1006
geteuid()                               = 1006
getgid()                                = 1002
getegid()                               = 1002
newfstatat(AT_FDCWD, "/home/zhangchen/.terminfo", 0x55611da162f0, 0) = -1 ENOENT (No such file or directory)
newfstatat(AT_FDCWD, "/etc/terminfo", {st_mode=S_IFDIR|0755, st_size=4096, ...}, 0) = 0
newfstatat(AT_FDCWD, "/lib/terminfo", {st_mode=S_IFDIR|0755, st_size=4096, ...}, 0) = 0
newfstatat(AT_FDCWD, "/usr/share/terminfo", {st_mode=S_IFDIR|0755, st_size=4096, ...}, 0) = 0
access("/etc/terminfo/x/xterm-256color", R_OK) = -1 ENOENT (No such file or directory)
access("/lib/terminfo/x/xterm-256color", R_OK) = 0
openat(AT_FDCWD, "/lib/terminfo/x/xterm-256color", O_RDONLY) = 3
newfstatat(3, "", {st_mode=S_IFREG|0644, st_size=3852, ...}, AT_EMPTY_PATH) = 0
read(3, "\36\2%\0&\0\17\0\235\1Z\6xterm-256color|xterm"..., 32768) = 3852
read(3, "", 28672)                      = 0
close(3)                                = 0
ioctl(1, TCGETS, {B38400 opost isig icanon echo ...}) = 0
ioctl(1, TCGETS, {B38400 opost isig icanon echo ...}) = 0
ioctl(1, TCGETS, {B38400 opost isig icanon echo ...}) = 0
ioctl(1, TCGETS, {B38400 opost isig icanon echo ...}) = 0
ioctl(1, TIOCGWINSZ, {ws_row=21, ws_col=200, ws_xpixel=0, ws_ypixel=0}) = 0
ioctl(0, TIOCGWINSZ, {ws_row=21, ws_col=200, ws_xpixel=0, ws_ypixel=0}) = 0
brk(0x55611da41000)                     = 0x55611da41000
rt_sigprocmask(SIG_SETMASK, [], NULL, 8) = 0
--- SIGCHLD {si_signo=SIGCHLD, si_code=CLD_EXITED, si_pid=661036, si_uid=1006, si_status=0, si_utime=0, si_stime=0} ---
wait4(-1, 0x7fff55dc2210, WNOHANG, NULL) = -1 ECHILD (No child processes)
rt_sigreturn({mask=[]})                 = 0
read(255, "", 11)                       = 0
rt_sigprocmask(SIG_BLOCK, [CHLD], [], 8) = 0
rt_sigprocmask(SIG_SETMASK, [], NULL, 8) = 0
exit_group(0)                           = ?
+++ exited with 0 +++

        令人疑惑的是,其中只有一个clone调用,即clone()=661036,这是为了创建子shell,而在这之后,并没有像上面那样再次为了sleep命令首先clone后调用execve替换的操作,而是直接进行了execve替换,即[pid 661036] execve("/usr/bin/sleep", ["sleep", "20"], 0x55611da10b60 /* 54 vars */)=0,这是bash进行了优化,即当其发现子shell中只需执行一条命令时,其直接调用execve替换,省略了一个clone创建子进程的过程。这么做的结果会导致我们无法使用ps观察到子shell,因为其已经被替换为sleep子进程,如下所示。

UID          PID    PPID  C STIME TTY          TIME CMD
zhangch+  661032  660255  0 13:52 pts/20   00:00:00 strace -f bash test.sh
zhangch+  661035  661032  0 13:52 pts/20   00:00:00 bash test.sh
zhangch+  661036  661035  0 13:52 pts/20   00:00:00 sleep 20

        子shell不是一般的子进程,它能继承父进程的所有变量,无论其是否导出,因为只执行了clone的调用,下面是一个例子。

​# 文件test.sh
#############################
a=1
(echo $a)
#############################$ bash test.sh
输出:1

        可能有人会认为这里是$a在父进程就进行了变量展开,这是错误的,一个命令只有在执行前才会进行变量展开,而不是解析时,详细信息可以参考下面的这篇文章。Linux:执行命令的命令eval与Bash解析命令的方式_linux bash解析-CSDN博客

        我们可以换一个思路,以便绕开上面的困境,Bash提供了三个特殊的变量,分别是$BASHPID、$BASH_SUBSHELL和$SHLVL。

        $BASHPID是对于每个shell都是唯一的(其实就是进程号),这包括使用bash命令创建的shell和上面谈到的子shell,例如下面的脚本。

​# 文件test.sh
#############################
echo $BASHPID
(echo $BASHPID)
#############################$ bash test.sh输出:
681607
681608

        $BASH_SUBSHELL是专门为子shell设计的变量,对于普通的shell,其值为0,对于一层子shell,其值为1...以此类推,例如下面的脚本。

​# 文件test.sh
#############################
echo $BASH_SUBSHELL
(echo $BASH_SUBSHELL;(echo $BASH_SUBSHELL))
#############################$ bash test.sh输出:
0
1
2

         $SHLVL是专门为普通递归创建的shell设计的环境变量,当进入了一个login shell,其值会被设定为1,每当创建了一个普通的nonlogin shell进程时,继承后的$SHLVL变量值会加1,如下所示。

$ su -l *****
Password: 
$ echo $SHLVL
1
$ bash
$ echo $SHLVL
2​# 文件test.sh
#############################
echo $SHLVL
(echo $SHLVL)
#############################$ bash test.sh输出:
2
2

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

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

相关文章

Vue3使用mitt进行组件通信

mitt&#xff1a;事件总线&#xff0c;是第三方插件。 Vue2.x 使用 EventBus 事件总线进行兄弟组件通信&#xff0c;而在Vue3中 EventBus 事件总线模式已经被移除&#xff0c;官方建议使用外部的、实现了事件触发器接口的库&#xff0c;例如 mitt 或 tiny-emitter。 比起 Vue…

rtos最小任务切换的实现 keil软件仿真 stm32 PendSV

最小任务切换的实现 本例子实现了一个 rtos 最小的任务切换功能&#xff0c;使用 keil 仿真功能&#xff0c;在模拟的 stm32f103 的器件上实现了使用 PendSV 中断切换线程的效果。 git 源码仓库&#xff1a;https://github.com/yutianos/rtos-little 本文链接&#xff1a;csdn…

数学函数,字符串

目录 Math类 三角函数 指数函数 取整方法 其他方法 String类 常见方法 字符串比较方法 子串和数字与字符串的转换 Math类 Math类在java.lang中&#xff0c;不用显式引入。 三角函数 private static void triangleFunc() {double degree Math.toDegrees(Math.PI / 3…

神经网络与深度学习——第4章 前馈神经网络

本文讨论的内容参考自《神经网络与深度学习》https://nndl.github.io/ 第4章 前馈神经网络 前馈神经网络 神经元 Sigmoid型函数 Hard-Logistic函数和Hard-Tanh函数 ReLU函数 带泄露的ReLU 带参数的ReLU ELU函数 Softplus函数 Swish函数 GELU函数 Maxout单元 网络结构 前馈网络…

Qt图像处理技术九:得到QImage图像的灰度直方图

效果 原理 得到灰度化值&#xff0c;将灰度化的值带入0-255内&#xff0c;增加&#xff0c;得到可视化图形 源码 // 绘制直方图 QImage drawHistogram(const QImage &image) {QVector<int> histogram(256, 0);// 计算图像的灰度直方图for (int y 0; y < image…

【SpringBoot】SpringBoot整合JWT

目录 先说token单点登录&#xff08;SSO&#xff09;简介原理单点登录的优势单点登录流程分布式单点登录方式方式一&#xff1a;session广播机制实现方式二&#xff1a;使用cookieredis实现。方式三&#xff1a;token认证 JWT数字签名JWT的作用JWT和传统Session1、无状态&#…

linux nohup命令详解:持久运行命令,无视终端退出

nohup &#xff08;全称为 “no hang up”&#xff09;&#xff0c;用于运行一个命令&#xff0c;使其在你退出 shell 或终端会话后继续运行。 基本语法 nohup command [arg1 ...] [&> output_file] &command 是你想要运行的命令。[arg1 ...] 是该命令的参数。&am…

微服务学习Day8

文章目录 Sentinel雪崩问题服务保护框架Sentinel配置 限流规则快速入门流控模式流控效果热点参数限流 隔离和降级FeignClient整合Sentinel线程隔离&#xff08;舱壁模式&#xff09;熔断降级 授权规则及规则持久化授权规则自定义异常结果持久化 Sentinel 雪崩问题 服务保护框架…

让WSL内核使用BBR拥塞控制算法

使用git命令从Linux内核的Git仓库中获取源代码,$ git clone --depth 1 https://github.com/microsoft/WSL2-Linux-Kernel.git,找到对应的内核版本$ git log --grep="5.15.146.1-microsoft-standard-WSL2",回退到本机安装的内核版本$ git checkout <commit-id&…

无界延迟队列DelayQueue

一:介绍 DelayQueue是一个无界的BlockingQueue,用于放置实现了Delayed接口的对象,其中的对象只能在其到期时才能从队列中取走。这种队列是有序的,即队头对象的延迟到期时间最长。注意:不能将null元素放置到这种队列中。 二: DelayQueue基本原理 DelayQueue是一个没有边界…

代码随想录算法训练营第十天|232.用栈实现队列、225. 用队列实现栈

232.用栈实现队列 题目链接&#xff1a;232. 用栈实现队列 文档讲解&#xff1a;代码随想录 状态&#xff1a;写出来 &#xff0c;但差强人意 思路&#xff1a; 定义两个容器&#xff0c;可以是Stack&#xff0c;也可以是Deque&#xff0c;stackIn相当于临时容器,用来存放元素&…

git随记

git status 查看文件状态 git status -s 比较简洁的查看文件状态。如下代表此文件是新建的&#xff0c;没有被git跟踪的文件&#xff1a; $ git status -s ?? abc.txtgit add abc.txt 将abc添加到暂存区。后再次git status -s $ git status -s A abc.txtgit reset 将暂存…

嵌入式开发--stm32cubeprogrammer写入选项字节

需要在批量烧写时写入选项字节&#xff0c;操作如下&#xff1a; 在下载页面&#xff0c;勾选选项字节命令&#xff0c; 输入以下命令&#xff0c;后面的0xBB表示选项字节是bb&#xff0c;表示读保护&#xff0c;也可以按需要写其他的字符 -ob rdp0xBB在需要的功能前打上勾&a…

知识图谱抽取实战

相关代码见文末 1.知识图谱应用场景 知识图谱是一种先进的数据组织形式,它通过图数据结构来表示实体(如人、地点、概念)及其之间的复杂关系,便于机器理解和处理。这种结构化知识库允许高效的信息检索、推理和知识发现,尤其适用于处理高度关联且需要深度理解的领域,如医学…

解决wireshark无法抓取mysql数据报文

我前几天在用wireshark抓取mysql协议&#xff0c;只能看到登录信息&#xff0c;完全看不到具体报文。显示如下&#xff1a; 找了多资料&#xff0c;我也没解决这问题。但用公司测试环境的数据库就能抓取到mysql数据报文&#xff0c;观察了下公司的数据库就只发现连接url上多了…

使用 Django Channels 构建实时聊天应用(包含用户认证和消息持久化)

文章目录 准备工作创建 Django 项目创建应用程序配置项目编写 Consumer编写路由创建 URL 路由运行应用用户认证消息持久化显示历史消息结论 Django Channels 是 Django 的一个扩展&#xff0c;允许在 Web 应用中添加实时功能&#xff0c;例如 Websockets、HTTP2 和其他协议。本…

oracle mysql索引区别

文章目录 1.引言1.1 索引的基本概念1.2 Oracle和MySQL的简介 2.Oracle索引2.1 Oracle索引的类型**B-Tree索引****Bitmap索引****Function-Based索引****Partitioned索引****Text索引** 2.2 Oracle索引的工作原理2.3 Oracle索引的实例代码 3.MySQL索引3.1 MySQL索引的类型**B-Tr…

[PyQt5] 窗口接收WM_COPY消息

#本程序是python qt5 创建的窗口&#xff0c;拦截外部消息给窗口发送的WM_COPY消息并显示出来。一般是用来作为窗口之间的通讯机制之一。 python文件如下&#xff1a;qt5拦截消息 #!/usr/bin/env python3 # -*- coding: utf-8 -*- import sys from PyQt5.QtWidgets import QAp…

STM32-14-FSMC_LCD

STM32-01-认识单片机 STM32-02-基础知识 STM32-03-HAL库 STM32-04-时钟树 STM32-05-SYSTEM文件夹 STM32-06-GPIO STM32-07-外部中断 STM32-08-串口 STM32-09-IWDG和WWDG STM32-10-定时器 STM32-11-电容触摸按键 STM32-12-OLED模块 STM32-13-MPU 文章目录 1. 显示器分类2. LCD简…

掌握 NestJS 10.x:从零开始构建高效可扩展的服务器端应用详解

NestJS 是一个用于构建高效、可扩展的 Node.js 服务端应用的框架&#xff0c;基于 TypeScript 构建&#xff0c;并且受 Angular 的启发&#xff0c;提供了模块化、易测试、易维护的架构。NestJS 10.x 引入了一些新特性和改进&#xff0c;进一步提升了开发体验。本文将详细介绍如…