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.sh

sleep 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

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

如若内容造成侵权/违法违规/事实不符,请联系我们进行投诉反馈qq邮箱809451989@qq.com,一经查实,立即删除!

相关文章

Python 将Word、Excel、PDF、PPT文档转为OFD文档

OFD&#xff08;Open Fixed-layout Document &#xff09;是我国自主制定的一种开放版式文件格式标准。OFD文档具有不易被篡改、格式独立、版式固定等特点&#xff0c;目前常用于政府公文、金融、电子发票等领域。 如果想要通过Python将Office文档&#xff08;如Word、Excel或…

02-CSS3基本样式

目录 1. CSS3简介 1.1 CSS3的兼容情况 1.2 优雅降级和渐进增强的开发思想 2. 新增选择器 2.1 选择相邻兄弟 2.2 匹配选择器 2.3 属性选择器(重点) 2.4 结构性伪类选择器&#xff08;重点&#xff09; 2.4.1 整体结构类型 2.4.2 标签结构类型 2.4.3 指定子元素的序号&…

机器人系统ros2-开发学习实践16-RViz 用户指南

RViz 是 ROS&#xff08;Robot Operating System&#xff09;中的一个强大的 3D 可视化工具&#xff0c;用于可视化机器人模型、传感器数据、路径规划等。以下是RViz用户指南&#xff0c;帮助你了解如何使用RViz来进行机器人开发和调试。 启动可视化工具 ros2 run rviz2 rviz2…

C++ day2 练习

思维导图 自己封装一个矩形类(Rect)&#xff0c;拥有私有属性:宽度(width)、高度(height)&#xff0c; 定义公有成员函数: 初始化函数:void init(int w, int h) 更改宽度的函数:set_w(int w) 更改高度的函数:set_h(int h) 输出该矩形的周长和面积函数:void show() #inclu…

中间件复习之-消息队列

消息队列在分布式架构的作用 消息队列&#xff1a;在消息的传输过程中保存消息的容器&#xff0c;生产者和消费者不直接通讯&#xff0c;依靠队列保证消息的可靠性&#xff0c;避免了系统间的相互影响。 主要作用&#xff1a; 业务解耦异步调用流量削峰 业务解耦 将模块间的…

go 针对 time类型字段,前端查询,后端返回数据格式为UTC时间

测试代码 package mainimport ("context""log""net/http""time""github.com/gin-gonic/gin""go.mongodb.org/mongo-driver/bson""go.mongodb.org/mongo-driver/bson/primitive""go.mongodb.org/m…

微信、支付宝新规:单笔交易超过3000元将受抽查!风控更为严格!

就在近段时间&#xff0c;网上出现了大量的传言&#xff0c;5月起微信、支付宝新规&#xff0c;单笔交易金额超过3000元就会面临抽查的风险&#xff1f;这一言论引起不少的恐慌&#xff0c;纷纷表示出抵触的心理。 为了有效打击这些不法行为&#xff0c;维护金融市场的健康稳定…

计算机组成原理·海明编码及其实验

前言&#xff1a;海明编码这一块在刚开始的时候没有弄懂&#xff0c;后面通过做实验、复习慢慢摸清了门道。在学习计算机组成原理的过程中&#xff0c;实验实践是很重要的&#xff0c;它会让你去搞清楚事情背后的原理&#xff0c;逼着你学会你没听懂的东西。这篇文章会从海明码…

【UnityShader入门精要学习笔记】第十六章 Unity中的渲染优化技术 (上)

本系列为作者学习UnityShader入门精要而作的笔记&#xff0c;内容将包括&#xff1a; 书本中句子照抄 个人批注项目源码一堆新手会犯的错误潜在的太监断更&#xff0c;有始无终 我的GitHub仓库 总之适用于同样开始学习Shader的同学们进行有取舍的参考。 文章目录 移动平台上…

一站式链路追踪:阿里云的端到端解决方案

作者&#xff1a;涯海 炎炎夏日&#xff0c;当你打开外卖 APP 购买奶茶却发现下单失败&#xff1b;五一佳节&#xff0c;当你自驾游途中发现导航响应缓慢&#xff0c;频繁错过路口&#xff1b;深更半夜&#xff0c;当你辅导孩子功课&#xff0c;却发现 GPT 应用迟迟无法应答。…

使用画图工具修改图片文字

方法思路&#xff1a; 使用背景色将需要修改的文字覆盖&#xff0c;然后在原来的地方加入修改后的字。 第一步&#xff1a; 选中图片后右键&#xff0c;选择“编辑”&#xff08;默认会使用画图工具打开&#xff09; 第二步&#xff1a; 选取颜色选取器&#xff0c;如下图 使…

探索Lora:微调大型语言模型和扩散模型的低秩适配方法【原理解析,清晰简洁易懂!附代码】

探索Lora&#xff1a;微调大型语言模型和扩散模型的低秩适配方法 随着深度学习技术的快速发展&#xff0c;大型语言模型&#xff08;LLMs&#xff09;和扩散模型&#xff08;Diffusion Models&#xff09;在自然语言处理和计算机视觉领域取得了显著的成果。然而&#xff0c;这…

【tomcat 源码分析总结】

文章目录 tomcat官网路径目录结构介绍&#xff1a;Tomcat 系统架构 和 原理剖析http 的请求的处理过程 Tomcat 请求处理大致过程 tomcat官网路径 目录结构介绍&#xff1a; confserver.xml 端口的指定tomcat-users.xml 角色web.xml : tomcat 全局的xmllogging.properties 日志…

项目管理主要文档介绍

1、商业论证&#xff1a;一般由项目发起人创建&#xff0c;用于论证项目是否对组织有财务方面的收益。商业论证创建于项日开始之前&#xff0c;用于判断项目是否需要被开展。 2、项目章程&#xff1a;一般由项日经理创建,并由发起入和关键相关力提供输人&#xff0c;最后经项目…

长难句打卡5.31

In a workplace that’s fundamentally indifferent to your life and its meaning, office speak can help you figure out how you relate to your work—and how your work defines who you are. 在一个对你的生活和生活意义漠不关心的工作场所中&#xff0c;办公室语言可以…

ArcGIS空间数据处理、空间分析与制图;PLUS模型和InVEST模型的原理,参量提取与模型运行及结果分析;土地利用时空变化以及对生态系统服务的影响分析

工业革命以来&#xff0c;社会生产力迅速提高&#xff0c;人类活动频繁&#xff0c;此外人口与日俱增对土地的需求与改造更加强烈&#xff0c;人-地关系日益紧张。此外&#xff0c;土地资源的不合理开发利用更是造成了水土流失、植被退化、水资源短缺、区域气候变化、生物多样性…

禁用USB端口的办法,哪一种禁用USB端口的方法好

禁用USB端口的办法&#xff0c;哪一种禁用USB端口的方法好 禁用USB端口是保护公司数据安全的一种常见做法&#xff0c;旨在防止未经授权的数据传输和潜在的恶意软件传播。以下是几种常见的禁用USB端口方法及其效果评价。 1、硬件方法&#xff1a; BIOS设置&#xff1a;通过BIO…

Android下HWC以及drm_hwcomposer普法(下)

Android下HWC以及drm_hwcomposer普法(下) 引言 不容易啊&#xff0c;写到这里。经过前面的普法(上)&#xff0c;我相信童鞋们对HWC和drm_hwcomposer已经有了一定的认知了。谷歌出品&#xff0c;必须精品。我们前面的篇章见分析到啥来了&#xff0c;对了分析到了HwcDisplay::in…

2024年,抖音小店618十大爆款预测!商家抓紧时间上架!

哈喽~我是电商月月 做电商的玩家都知道&#xff0c;一但到了换季或者是节日大促的时候&#xff0c;销量高&#xff0c;是最容易爆单的阶段 而提前上架一些热卖产品&#xff0c;爆单的几率在自己的店铺机会就越大 而最近的一个大型活动&#xff0c;就是618了&#xff0c;抖音…

【C++ ——— 继承】

文章目录 继承的概念即定义继承概念继承定义定义格式继承关系和访问限定符继承基类成员访问方式的变化 基类对象和派生类对象的赋值转换继承中的作用域派生类中的默认成员函数继承与友元继承与静态成员菱形继承虚继承解决数据冗余和二义性的原理继承的总结继承常见笔试面试题 继…