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

news2024/11/25 13:31:14

相关阅读

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

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

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

相关文章

SpringBoot发送Gmail邮件

1. 登录Gmail Gmail网址 点击右上角“小齿轮”&#xff0c;然后点击"查看所有设置" 点击“转发和 POP/IMAP”&#xff0c;按图中设置&#xff0c;然后点击保存&#xff1a; 2. 启用两步验证(https://myaccount.google.com/security) 登录上述网址&#xff0c;找…

msvcp100.dll丢失怎样修复?几种快速有效修复msvcp100.dll丢失的方法

在使用电脑时是不是遇到过关于msvcp100.dll丢失文件丢失的情况&#xff1f;出现这样的情况有什么办法可以将丢失的msvcp100.dll文件快速恢复&#xff1f;今天的这篇文章就将教大家几种能够有效的解决msvcp100.dll丢失问题的方法。 方法一&#xff1a;重启电脑 重启电脑是一种简…

jmeter多用户登录并退出教程

有时候为了模拟更真实的场景&#xff0c;在项目中需要多用户登录并退出操作&#xff0c;大致参考如下 多用户登录前面已经实现&#xff1a;参考博文 多用户登录并退出jmx文件&#xff1a;百度网盘 提取码&#xff1a;0000 一、多用户退出操作 添加一个setUp线程组&#xff0…

基恩士激光 速度 曝光等关系

一、基恩士 CtrlN 二、速度设置 计算扫描速度 曝光时间&#xff1a; 1:1 相机点间隔是0.025 &#xff0c;我们要扫描的图像也是1&#xff1a;1的话&#xff0c;速度可以为 采样周期我们设定为3K&#xff0c;假如我们的7000行就够了 速度V0.025&#xff08;线间隔&#xff0…

YOLOv10全网最新创新点改进系列:YOLOv10改进加入新型高效的多尺度注意力(EMA)模块保留每个通道的信息并减少计算成本!助力v10检测性能遥遥领先!

YOLOv10全网最新创新点改进系列&#xff1a;YOLOv10改进加入新型高效的多尺度注意力&#xff08;EMA&#xff09;模块保留每个通道的信息并减少计算成本&#xff01;助力v10检测性能遥遥领先&#xff01; 所有改进代码均经过实验测试跑通&#xff01; 此项目不低于30种改进&am…

hadoop(1)--hdfs部署(亲测可用)

一、准备&#xff1a; 1、三台集群部署&#xff0c;配置hosts #cat /etc/hosts 192.168.46.128 node1 #nameNode dataNode secondaryNameNode 192.168.46.129 node2 #datanode 192.168.46.130 node3 #datanode说明&#xff1a; NameNode: 主节点管理者 DataNode&…

解决el-dialog里嵌入el-tabs卡死的问题

文章目录 1. 解决 el-dialog 里嵌入 el-tabs 卡死的问题 1. 解决 el-dialog 里嵌入 el-tabs 卡死的问题 今天发现在element ui里面使用 el-dialog 会导致页面卡死&#xff0c;本来我心想这么简单的一个弹窗&#xff0c;怎么会卡死解决思路&#xff1a;以为是项目的问题&#x…

展台搭建时打造完美的展示空间

1、确定主题和目标 在展台设计搭建之前&#xff0c;需要明确展示的主题和目标&#xff0c;包括展示内容、目标观众、品牌形象等。这有助于为展台设计搭建提供明确的方向和指导。 2、精细化设计 展台设计需要精细化&#xff0c;注重每一个细节的把控。包括展台结构、色彩搭配、材…

4. MySQL 约束

文章目录 【 1. 主键约束 PRIMARY KEY 】1.1 在创建表时设置主键约束设置单字段主键在创建表时设置联合主键 1.2 在修改表时添加主键约束1.3 删除主键约束1.4 主键自增长 AUTO_INCREMENT指定自增字段初始值自增字段不连续 【 2. 外键约束 FOREIGN KEY 】2.1 在创建表时设置外键…

探索无限可能:API平台引领数据驱动的新时代

在数字化浪潮的推动下&#xff0c;数据已成为推动商业创新和增长的核心动力。然而&#xff0c;数据的获取、整合和应用并非易事&#xff0c;需要跨越技术、安全和效率等多重挑战。幸运的是&#xff0c;API&#xff08;应用程序接口&#xff09;平台的出现&#xff0c;为我们打开…

使用 Django Model 构建强大的数据库模型

文章目录 创建一个简单的 Django Model迁移数据库使用 Django Shell 操作模型Django Admin结论 在 Django 中&#xff0c;Model 是构建数据库模型的基础。它允许开发人员定义数据的结构&#xff0c;并提供了方便的方式来与数据库进行交互。本文将介绍如何使用 Django Model 来创…

LangChain之Agent代理(上)

LangChain之Agent代理 Agent代理概述分类 Agent的基本使用准备操作定义工具1.Tavily在线搜索2.创建检索器3.得到工具列表 初始化大模型创建Agent运行Agent添加记忆 Agent代理 概述 Agent代理的核心思想是使用语言模型来选择要采取的一系列动作。在链中&#xff0c;动作序列是硬…

IP地址在字符串形式、数字形式和byte数组中的转换

IP地址 ip地址,我们以ipv4为例,字符串形式为:“192.168.0.1”,可以转换成dword类型的数据: on key a {char ipv4AddrStr[16] = "192.168.0.1";//16进制:c0.a8.0.1dword ipv4AddrNum;ipv4AddrNum = ipGetAddressAsNumber(ipv4AddrStr);write("ipv4AddrNu…

Linus Torvalds把控着linux内核开发审核,他去世之后linux内核会怎样?

在开始前刚好我有一些资料&#xff0c;是我根据网友给的问题精心整理了一份「linux的资料从专业入门到高级教程」&#xff0c; 点个关注在评论区回复“888”之后私信回复“888”&#xff0c;全部无偿共享给大家&#xff01;&#xff01;&#xff01; Linus Torvalds 是 Linux…

【算法】模拟算法——替换所有的问号(easy)

题解&#xff1a;替换所有的问好(模拟算法) 目录 1.题目2.题解3.参考代码4.总结 1.题目 题目链接&#xff1a;LINK 2.题解 纯模拟。从前往后遍历整个字符串&#xff0c;找到问号之后&#xff0c;就⽤ a ~ z 的每⼀个字符去尝试替换即可。 3.参考代码 class Solution { pu…

下载安装nvm,使用nvm管理node.js版本

目录 一、下载安装nvm&#xff08;windows&#xff09; 二、使用nvm管理node.js版本 &#xff08;1&#xff09;nvm命令行 &#xff08;2&#xff09; 使用nvm管理node.js版本 ①查看nvm版本 ②显示活动的node.js版本 ③列出可供下载的node.js版本 ④安装node.js指定版本 ⑤列出…

36个JavaScript特效教程,学完即精通

课程目录 &#x1f9d1;‍&#x1f4bb;36个JavaScript特效教程&#xff0c;学完即精通 &#x1f381;【更多好课】资源仓库&#xff0c;海量资源&#xff0c;无偿分享√ 本站所有素材均来自于互联网&#xff0c;版权属原著所有&#xff0c;如有需要请购买正版。如有侵权&…

【测试】linux快捷指令工具cxtool

简介 登录linux时,我们经常需要重复输入一些指令. 这个工具可以把这些指令预置,需要的时候鼠标一点,会自动按预置的字符敲击键盘,敲击出指令. 下载地址 https://download.csdn.net/download/bandaoyu/89379371 使用方法 1,编辑配置文件&#xff0c;自定义自己的快捷指令。 2…

2024年最具性价比宠物空气净化器推荐!小米、希喂、安德迈真实测评

一款理想的宠物空气净化器应该具备去除浮毛和异味等基本功能&#xff0c;但要找到一款既满足个人需求、性能出色且性价比高的产品&#xff0c;这需要一定的选择技巧。 遗憾的是&#xff0c;许多人在购买时由于对相关术语的不熟悉或缺乏挑选经验&#xff0c;可能会买到不适合自…

资深开发推荐的IDEA 插件

开发如虎添翼 工欲善其事&#xff0c;必先利其器。想要提升编程开发效率&#xff0c;必须选择一款顺手的开发工具&#xff0c;插件不在多&#xff0c;而在精&#xff0c;作为从业10年的程序员&#xff0c;我目前用到这十几个插件&#xff0c;在平时开发&#xff0c;代码review…