当前位置:   article > 正文

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

linux subshell

相关阅读

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解释执行这个脚本过程中的系统调用。

  1. # 文件test.sh
  2. sleep 20
$ strace -f bash test.sh  # 需要加上-f选项,这样才能追踪子进程
  1. execve("/usr/bin/bash", ["bash", "test.sh"], 0x7ffe5b2df940 /* 55 vars */) = 0
  2. brk(NULL) = 0x55cfde987000
  3. arch_prctl(0x3001 /* ARCH_??? */, 0x7fff3394b3b0) = -1 EINVAL (Invalid argument)
  4. mmap(NULL, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fa2e2cac000
  5. access("/etc/ld.so.preload", R_OK) = -1 ENOENT (No such file or directory)
  6. openat(AT_FDCWD, "/etc/ld.so.cache", O_RDONLY|O_CLOEXEC) = 3
  7. newfstatat(3, "", {st_mode=S_IFREG|0644, st_size=95179, ...}, AT_EMPTY_PATH) = 0
  8. mmap(NULL, 95179, PROT_READ, MAP_PRIVATE, 3, 0) = 0x7fa2e2c94000
  9. close(3) = 0
  10. openat(AT_FDCWD, "/lib/x86_64-linux-gnu/libtinfo.so.6", O_RDONLY|O_CLOEXEC) = 3
  11. 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
  12. newfstatat(3, "", {st_mode=S_IFREG|0644, st_size=200136, ...}, AT_EMPTY_PATH) = 0
  13. mmap(NULL, 203040, PROT_READ, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x7fa2e2c62000
  14. mmap(0x7fa2e2c70000, 69632, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0xe000) = 0x7fa2e2c70000
  15. mmap(0x7fa2e2c81000, 57344, PROT_READ, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x1f000) = 0x7fa2e2c81000
  16. mmap(0x7fa2e2c8f000, 20480, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x2c000) = 0x7fa2e2c8f000
  17. close(3) = 0
  18. openat(AT_FDCWD, "/lib/x86_64-linux-gnu/libc.so.6", O_RDONLY|O_CLOEXEC) = 3
  19. 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
  20. 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
  21. 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
  22. 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
  23. newfstatat(3, "", {st_mode=S_IFREG|0755, st_size=2220400, ...}, AT_EMPTY_PATH) = 0
  24. 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
  25. mmap(NULL, 2264656, PROT_READ, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x7fa2e2a00000
  26. mprotect(0x7fa2e2a28000, 2023424, PROT_NONE) = 0
  27. mmap(0x7fa2e2a28000, 1658880, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x28000) = 0x7fa2e2a28000
  28. mmap(0x7fa2e2bbd000, 360448, PROT_READ, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x1bd000) = 0x7fa2e2bbd000
  29. mmap(0x7fa2e2c16000, 24576, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x215000) = 0x7fa2e2c16000
  30. mmap(0x7fa2e2c1c000, 52816, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0x7fa2e2c1c000
  31. close(3) = 0
  32. mmap(NULL, 12288, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fa2e2c5f000
  33. arch_prctl(ARCH_SET_FS, 0x7fa2e2c5f740) = 0
  34. set_tid_address(0x7fa2e2c5fa10) = 4064924
  35. set_robust_list(0x7fa2e2c5fa20, 24) = 0
  36. rseq(0x7fa2e2c600e0, 0x20, 0, 0x53053053) = 0
  37. mprotect(0x7fa2e2c16000, 16384, PROT_READ) = 0
  38. mprotect(0x7fa2e2c8f000, 16384, PROT_READ) = 0
  39. mprotect(0x55cfdd194000, 16384, PROT_READ) = 0
  40. mprotect(0x7fa2e2ce6000, 8192, PROT_READ) = 0
  41. prlimit64(0, RLIMIT_STACK, NULL, {rlim_cur=8192*1024, rlim_max=RLIM64_INFINITY}) = 0
  42. munmap(0x7fa2e2c94000, 95179) = 0
  43. openat(AT_FDCWD, "/dev/tty", O_RDWR|O_NONBLOCK) = 3
  44. close(3) = 0
  45. getrandom("\x34\xa4\x2c\xab\x9e\xab\xb9\x29", 8, GRND_NONBLOCK) = 8
  46. brk(NULL) = 0x55cfde987000
  47. brk(0x55cfde9a8000) = 0x55cfde9a8000
  48. openat(AT_FDCWD, "/usr/lib/locale/locale-archive", O_RDONLY|O_CLOEXEC) = 3
  49. newfstatat(3, "", {st_mode=S_IFREG|0644, st_size=8872448, ...}, AT_EMPTY_PATH) = 0
  50. mmap(NULL, 8872448, PROT_READ, MAP_PRIVATE, 3, 0) = 0x7fa2e2000000
  51. close(3) = 0
  52. openat(AT_FDCWD, "/usr/lib/x86_64-linux-gnu/gconv/gconv-modules.cache", O_RDONLY) = 3
  53. newfstatat(3, "", {st_mode=S_IFREG|0644, st_size=27002, ...}, AT_EMPTY_PATH) = 0
  54. mmap(NULL, 27002, PROT_READ, MAP_SHARED, 3, 0) = 0x7fa2e2ca5000
  55. close(3) = 0
  56. futex(0x7fa2e2c1ba6c, FUTEX_WAKE_PRIVATE, 2147483647) = 0
  57. getuid() = 1006
  58. getgid() = 1002
  59. geteuid() = 1006
  60. getegid() = 1002
  61. rt_sigprocmask(SIG_BLOCK, NULL, [], 8) = 0
  62. ioctl(-1, TIOCGPGRP, 0x7fff3394b2a4) = -1 EBADF (Bad file descriptor)
  63. 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
  64. 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
  65. 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
  66. 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
  67. 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
  68. 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
  69. 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
  70. 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
  71. 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
  72. 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
  73. 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
  74. 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
  75. 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
  76. rt_sigprocmask(SIG_BLOCK, NULL, [], 8) = 0
  77. 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
  78. uname({sysname="Linux", nodename="liubo-SYS-7048GR-TR", ...}) = 0
  79. newfstatat(AT_FDCWD, "/home/zhangchen", {st_mode=S_IFDIR|0750, st_size=4096, ...}, 0) = 0
  80. newfstatat(AT_FDCWD, ".", {st_mode=S_IFDIR|0750, st_size=4096, ...}, 0) = 0
  81. newfstatat(AT_FDCWD, "/home", {st_mode=S_IFDIR|0755, st_size=4096, ...}, 0) = 0
  82. newfstatat(AT_FDCWD, "/home/zhangchen", {st_mode=S_IFDIR|0750, st_size=4096, ...}, 0) = 0
  83. getpid() = 4064924
  84. getppid() = 4064921
  85. newfstatat(AT_FDCWD, ".", {st_mode=S_IFDIR|0750, st_size=4096, ...}, 0) = 0
  86. 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)
  87. newfstatat(AT_FDCWD, "/home/zhangchen/.conda/envs/DL/bin/bash", 0x7fff3394aee0, 0) = -1 ENOENT (No such file or directory)
  88. newfstatat(AT_FDCWD, "/opt/miniconda3/condabin/bash", 0x7fff3394aee0, 0) = -1 ENOENT (No such file or directory)
  89. newfstatat(AT_FDCWD, "/opt/miniconda3/bin/bash", 0x7fff3394aee0, 0) = -1 ENOENT (No such file or directory)
  90. newfstatat(AT_FDCWD, "/usr/local/sbin/bash", 0x7fff3394aee0, 0) = -1 ENOENT (No such file or directory)
  91. newfstatat(AT_FDCWD, "/usr/local/bin/bash", 0x7fff3394aee0, 0) = -1 ENOENT (No such file or directory)
  92. newfstatat(AT_FDCWD, "/usr/sbin/bash", 0x7fff3394aee0, 0) = -1 ENOENT (No such file or directory)
  93. newfstatat(AT_FDCWD, "/usr/bin/bash", {st_mode=S_IFREG|0755, st_size=1396520, ...}, 0) = 0
  94. newfstatat(AT_FDCWD, "/usr/bin/bash", {st_mode=S_IFREG|0755, st_size=1396520, ...}, 0) = 0
  95. geteuid() = 1006
  96. getegid() = 1002
  97. getuid() = 1006
  98. getgid() = 1002
  99. access("/usr/bin/bash", X_OK) = 0
  100. newfstatat(AT_FDCWD, "/usr/bin/bash", {st_mode=S_IFREG|0755, st_size=1396520, ...}, 0) = 0
  101. geteuid() = 1006
  102. getegid() = 1002
  103. getuid() = 1006
  104. getgid() = 1002
  105. access("/usr/bin/bash", R_OK) = 0
  106. newfstatat(AT_FDCWD, "/usr/bin/bash", {st_mode=S_IFREG|0755, st_size=1396520, ...}, 0) = 0
  107. newfstatat(AT_FDCWD, "/usr/bin/bash", {st_mode=S_IFREG|0755, st_size=1396520, ...}, 0) = 0
  108. geteuid() = 1006
  109. getegid() = 1002
  110. getuid() = 1006
  111. getgid() = 1002
  112. access("/usr/bin/bash", X_OK) = 0
  113. newfstatat(AT_FDCWD, "/usr/bin/bash", {st_mode=S_IFREG|0755, st_size=1396520, ...}, 0) = 0
  114. geteuid() = 1006
  115. getegid() = 1002
  116. getuid() = 1006
  117. getgid() = 1002
  118. access("/usr/bin/bash", R_OK) = 0
  119. getpid() = 4064924
  120. getppid() = 4064921
  121. getpid() = 4064924
  122. getppid() = 4064921
  123. getpgrp() = 4064921
  124. ioctl(2, TIOCGPGRP, [4064921]) = 0
  125. 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
  126. prlimit64(0, RLIMIT_NPROC, NULL, {rlim_cur=514857, rlim_max=514857}) = 0
  127. rt_sigprocmask(SIG_BLOCK, NULL, [], 8) = 0
  128. openat(AT_FDCWD, "test.sh", O_RDONLY) = 3
  129. newfstatat(AT_FDCWD, "test.sh", {st_mode=S_IFREG|0644, st_size=9, ...}, 0) = 0
  130. ioctl(3, TCGETS, 0x7fff3394b240) = -1 ENOTTY (Inappropriate ioctl for device)
  131. lseek(3, 0, SEEK_CUR) = 0
  132. read(3, "sleep 20\n", 80) = 9
  133. lseek(3, 0, SEEK_SET) = 0
  134. prlimit64(0, RLIMIT_NOFILE, NULL, {rlim_cur=1024*1024, rlim_max=1024*1024}) = 0
  135. fcntl(255, F_GETFD) = -1 EBADF (Bad file descriptor)
  136. dup2(3, 255) = 255
  137. close(3) = 0
  138. fcntl(255, F_SETFD, FD_CLOEXEC) = 0
  139. fcntl(255, F_GETFL) = 0x8000 (flags O_RDONLY|O_LARGEFILE)
  140. newfstatat(255, "", {st_mode=S_IFREG|0644, st_size=9, ...}, AT_EMPTY_PATH) = 0
  141. lseek(255, 0, SEEK_CUR) = 0
  142. read(255, "sleep 20\n", 9) = 9
  143. newfstatat(AT_FDCWD, ".", {st_mode=S_IFDIR|0750, st_size=4096, ...}, 0) = 0
  144. 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)
  145. newfstatat(AT_FDCWD, "/home/zhangchen/.conda/envs/DL/bin/sleep", 0x7fff3394ad30, 0) = -1 ENOENT (No such file or directory)
  146. newfstatat(AT_FDCWD, "/opt/miniconda3/condabin/sleep", 0x7fff3394ad30, 0) = -1 ENOENT (No such file or directory)
  147. newfstatat(AT_FDCWD, "/opt/miniconda3/bin/sleep", 0x7fff3394ad30, 0) = -1 ENOENT (No such file or directory)
  148. newfstatat(AT_FDCWD, "/usr/local/sbin/sleep", 0x7fff3394ad30, 0) = -1 ENOENT (No such file or directory)
  149. newfstatat(AT_FDCWD, "/usr/local/bin/sleep", 0x7fff3394ad30, 0) = -1 ENOENT (No such file or directory)
  150. newfstatat(AT_FDCWD, "/usr/sbin/sleep", 0x7fff3394ad30, 0) = -1 ENOENT (No such file or directory)
  151. newfstatat(AT_FDCWD, "/usr/bin/sleep", {st_mode=S_IFREG|0755, st_size=35328, ...}, 0) = 0
  152. newfstatat(AT_FDCWD, "/usr/bin/sleep", {st_mode=S_IFREG|0755, st_size=35328, ...}, 0) = 0
  153. geteuid() = 1006
  154. getegid() = 1002
  155. getuid() = 1006
  156. getgid() = 1002
  157. access("/usr/bin/sleep", X_OK) = 0
  158. newfstatat(AT_FDCWD, "/usr/bin/sleep", {st_mode=S_IFREG|0755, st_size=35328, ...}, 0) = 0
  159. geteuid() = 1006
  160. getegid() = 1002
  161. getuid() = 1006
  162. getgid() = 1002
  163. access("/usr/bin/sleep", R_OK) = 0
  164. newfstatat(AT_FDCWD, "/usr/bin/sleep", {st_mode=S_IFREG|0755, st_size=35328, ...}, 0) = 0
  165. newfstatat(AT_FDCWD, "/usr/bin/sleep", {st_mode=S_IFREG|0755, st_size=35328, ...}, 0) = 0
  166. geteuid() = 1006
  167. getegid() = 1002
  168. getuid() = 1006
  169. getgid() = 1002
  170. access("/usr/bin/sleep", X_OK) = 0
  171. newfstatat(AT_FDCWD, "/usr/bin/sleep", {st_mode=S_IFREG|0755, st_size=35328, ...}, 0) = 0
  172. geteuid() = 1006
  173. getegid() = 1002
  174. getuid() = 1006
  175. getgid() = 1002
  176. access("/usr/bin/sleep", R_OK) = 0
  177. rt_sigprocmask(SIG_BLOCK, NULL, [], 8) = 0
  178. rt_sigprocmask(SIG_BLOCK, [INT TERM CHLD], [], 8) = 0
  179. clone(child_stack=NULL, flags=CLONE_CHILD_CLEARTID|CLONE_CHILD_SETTID|SIGCHLD, child_tidptr=0x7fa2e2c5fa10) = 4064925
  180. strace: Process 4064925 attached
  181. [pid 4064924] rt_sigprocmask(SIG_SETMASK, [], NULL, 8) = 0
  182. [pid 4064925] set_robust_list(0x7fa2e2c5fa20, 24) = 0
  183. [pid 4064924] rt_sigprocmask(SIG_BLOCK, [CHLD], [], 8) = 0
  184. [pid 4064925] getpid( <unfinished ...>
  185. [pid 4064924] rt_sigprocmask(SIG_SETMASK, [], <unfinished ...>
  186. [pid 4064925] <... getpid resumed>) = 4064925
  187. [pid 4064924] <... rt_sigprocmask resumed>NULL, 8) = 0
  188. [pid 4064924] rt_sigprocmask(SIG_BLOCK, [CHLD], [], 8) = 0
  189. [pid 4064924] rt_sigaction(SIGINT, {sa_handler=0x55cfdd0abdc0, sa_mask=[], sa_flags=SA_RESTORER, sa_restorer=0x7fa2e2a42520}, <unfinished ...>
  190. [pid 4064925] close(255 <unfinished ...>
  191. [pid 4064924] <... rt_sigaction resumed>{sa_handler=SIG_DFL, sa_mask=[], sa_flags=SA_RESTORER, sa_restorer=0x7fa2e2a42520}, 8) = 0
  192. [pid 4064925] <... close resumed>) = 0
  193. [pid 4064924] wait4(-1, <unfinished ...>
  194. [pid 4064925] rt_sigprocmask(SIG_SETMASK, [], NULL, 8) = 0
  195. [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
  196. [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
  197. [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
  198. [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
  199. [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
  200. [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
  201. [pid 4064925] execve("/usr/bin/sleep", ["sleep", "20"], 0x55cfde998b60 /* 54 vars */) = 0
  202. [pid 4064925] brk(NULL) = 0x56531e557000
  203. [pid 4064925] arch_prctl(0x3001 /* ARCH_??? */, 0x7fff4b839270) = -1 EINVAL (Invalid argument)
  204. [pid 4064925] mmap(NULL, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f1758aa0000
  205. [pid 4064925] access("/etc/ld.so.preload", R_OK) = -1 ENOENT (No such file or directory)
  206. [pid 4064925] openat(AT_FDCWD, "/etc/ld.so.cache", O_RDONLY|O_CLOEXEC) = 3
  207. [pid 4064925] newfstatat(3, "", {st_mode=S_IFREG|0644, st_size=95179, ...}, AT_EMPTY_PATH) = 0
  208. [pid 4064925] mmap(NULL, 95179, PROT_READ, MAP_PRIVATE, 3, 0) = 0x7f1758a88000
  209. [pid 4064925] close(3) = 0
  210. [pid 4064925] openat(AT_FDCWD, "/lib/x86_64-linux-gnu/libc.so.6", O_RDONLY|O_CLOEXEC) = 3
  211. [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
  212. [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
  213. [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
  214. [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
  215. [pid 4064925] newfstatat(3, "", {st_mode=S_IFREG|0755, st_size=2220400, ...}, AT_EMPTY_PATH) = 0
  216. [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
  217. [pid 4064925] mmap(NULL, 2264656, PROT_READ, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x7f1758800000
  218. [pid 4064925] mprotect(0x7f1758828000, 2023424, PROT_NONE) = 0
  219. [pid 4064925] mmap(0x7f1758828000, 1658880, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x28000) = 0x7f1758828000
  220. [pid 4064925] mmap(0x7f17589bd000, 360448, PROT_READ, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x1bd000) = 0x7f17589bd000
  221. [pid 4064925] mmap(0x7f1758a16000, 24576, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x215000) = 0x7f1758a16000
  222. [pid 4064925] mmap(0x7f1758a1c000, 52816, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0x7f1758a1c000
  223. [pid 4064925] close(3) = 0
  224. [pid 4064925] mmap(NULL, 12288, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f1758a85000
  225. [pid 4064925] arch_prctl(ARCH_SET_FS, 0x7f1758a85740) = 0
  226. [pid 4064925] set_tid_address(0x7f1758a85a10) = 4064925
  227. [pid 4064925] set_robust_list(0x7f1758a85a20, 24) = 0
  228. [pid 4064925] rseq(0x7f1758a860e0, 0x20, 0, 0x53053053) = 0
  229. [pid 4064925] mprotect(0x7f1758a16000, 16384, PROT_READ) = 0
  230. [pid 4064925] mprotect(0x56531d334000, 4096, PROT_READ) = 0
  231. [pid 4064925] mprotect(0x7f1758ada000, 8192, PROT_READ) = 0
  232. [pid 4064925] prlimit64(0, RLIMIT_STACK, NULL, {rlim_cur=8192*1024, rlim_max=RLIM64_INFINITY}) = 0
  233. [pid 4064925] munmap(0x7f1758a88000, 95179) = 0
  234. [pid 4064925] getrandom("\xf0\x4d\x93\x81\xc9\x8a\x71\x74", 8, GRND_NONBLOCK) = 8
  235. [pid 4064925] brk(NULL) = 0x56531e557000
  236. [pid 4064925] brk(0x56531e578000) = 0x56531e578000
  237. [pid 4064925] openat(AT_FDCWD, "/usr/lib/locale/locale-archive", O_RDONLY|O_CLOEXEC) = 3
  238. [pid 4064925] newfstatat(3, "", {st_mode=S_IFREG|0644, st_size=8872448, ...}, AT_EMPTY_PATH) = 0
  239. [pid 4064925] mmap(NULL, 8872448, PROT_READ, MAP_PRIVATE, 3, 0) = 0x7f1757e00000
  240. [pid 4064925] close(3) = 0
  241. [pid 4064925] clock_nanosleep(CLOCK_REALTIME, 0, {tv_sec=20, tv_nsec=0}, 0x7fff4b8392c0) = 0
  242. [pid 4064925] close(1) = 0
  243. [pid 4064925] close(2) = 0
  244. [pid 4064925] exit_group(0) = ?
  245. [pid 4064925] +++ exited with 0 +++
  246. <... wait4 resumed>[{WIFEXITED(s) && WEXITSTATUS(s) == 0}], 0, NULL) = 4064925
  247. 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
  248. ioctl(2, TIOCGWINSZ, {ws_row=32, ws_col=200, ws_xpixel=0, ws_ypixel=0}) = 0
  249. ioctl(1, TCGETS, {B38400 opost isig icanon echo ...}) = 0
  250. getuid() = 1006
  251. geteuid() = 1006
  252. getgid() = 1002
  253. getegid() = 1002
  254. getuid() = 1006
  255. geteuid() = 1006
  256. getgid() = 1002
  257. getegid() = 1002
  258. newfstatat(AT_FDCWD, "/home/zhangchen/.terminfo", 0x55cfde99f160, 0) = -1 ENOENT (No such file or directory)
  259. newfstatat(AT_FDCWD, "/etc/terminfo", {st_mode=S_IFDIR|0755, st_size=4096, ...}, 0) = 0
  260. newfstatat(AT_FDCWD, "/lib/terminfo", {st_mode=S_IFDIR|0755, st_size=4096, ...}, 0) = 0
  261. newfstatat(AT_FDCWD, "/usr/share/terminfo", {st_mode=S_IFDIR|0755, st_size=4096, ...}, 0) = 0
  262. access("/etc/terminfo/x/xterm-256color", R_OK) = -1 ENOENT (No such file or directory)
  263. access("/lib/terminfo/x/xterm-256color", R_OK) = 0
  264. openat(AT_FDCWD, "/lib/terminfo/x/xterm-256color", O_RDONLY) = 3
  265. newfstatat(3, "", {st_mode=S_IFREG|0644, st_size=3852, ...}, AT_EMPTY_PATH) = 0
  266. read(3, "\36\2%\0&\0\17\0\235\1Z\6xterm-256color|xterm"..., 32768) = 3852
  267. read(3, "", 28672) = 0
  268. close(3) = 0
  269. ioctl(1, TCGETS, {B38400 opost isig icanon echo ...}) = 0
  270. ioctl(1, TCGETS, {B38400 opost isig icanon echo ...}) = 0
  271. ioctl(1, TCGETS, {B38400 opost isig icanon echo ...}) = 0
  272. ioctl(1, TCGETS, {B38400 opost isig icanon echo ...}) = 0
  273. ioctl(1, TIOCGWINSZ, {ws_row=32, ws_col=200, ws_xpixel=0, ws_ypixel=0}) = 0
  274. ioctl(0, TIOCGWINSZ, {ws_row=32, ws_col=200, ws_xpixel=0, ws_ypixel=0}) = 0
  275. brk(0x55cfde9c9000) = 0x55cfde9c9000
  276. rt_sigprocmask(SIG_SETMASK, [], NULL, 8) = 0
  277. --- SIGCHLD {si_signo=SIGCHLD, si_code=CLD_EXITED, si_pid=4064925, si_uid=1006, si_status=0, si_utime=0, si_stime=0} ---
  278. wait4(-1, 0x7fff3394a810, WNOHANG, NULL) = -1 ECHILD (No child processes)
  279. rt_sigreturn({mask=[]}) = 0
  280. read(255, "", 9) = 0
  281. rt_sigprocmask(SIG_BLOCK, [CHLD], [], 8) = 0
  282. rt_sigprocmask(SIG_SETMASK, [], NULL, 8) = 0
  283. exit_group(0) = ?
  284. +++ 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命令观察到进程的创建情况,如下所示。

  1. UID PID PPID C STIME TTY TIME CMD
  2. zhangch+ 4064921 4064501 0 14:19 pts/20 00:00:00 strace -f bash test.sh
  3. zhangch+ 4064924 4064921 0 14:19 pts/20 00:00:00 bash test.sh
  4. 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来检测一个命令是否为内建命令,如下所示。

  1. $ type cd
  2. cd is a shell builtin

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

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

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

  1. execve("/usr/bin/bash", ["bash", "test.sh"], 0x7ffcd0c34cb0 /* 55 vars */) = 0
  2. brk(NULL) = 0x5577b9e0f000
  3. arch_prctl(0x3001 /* ARCH_??? */, 0x7fffb1f38ed0) = -1 EINVAL (Invalid argument)
  4. mmap(NULL, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f584c4fd000
  5. access("/etc/ld.so.preload", R_OK) = -1 ENOENT (No such file or directory)
  6. openat(AT_FDCWD, "/etc/ld.so.cache", O_RDONLY|O_CLOEXEC) = 3
  7. newfstatat(3, "", {st_mode=S_IFREG|0644, st_size=95179, ...}, AT_EMPTY_PATH) = 0
  8. mmap(NULL, 95179, PROT_READ, MAP_PRIVATE, 3, 0) = 0x7f584c4e5000
  9. close(3) = 0
  10. openat(AT_FDCWD, "/lib/x86_64-linux-gnu/libtinfo.so.6", O_RDONLY|O_CLOEXEC) = 3
  11. 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
  12. newfstatat(3, "", {st_mode=S_IFREG|0644, st_size=200136, ...}, AT_EMPTY_PATH) = 0
  13. mmap(NULL, 203040, PROT_READ, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x7f584c4b3000
  14. mmap(0x7f584c4c1000, 69632, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0xe000) = 0x7f584c4c1000
  15. mmap(0x7f584c4d2000, 57344, PROT_READ, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x1f000) = 0x7f584c4d2000
  16. mmap(0x7f584c4e0000, 20480, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x2c000) = 0x7f584c4e0000
  17. close(3) = 0
  18. openat(AT_FDCWD, "/lib/x86_64-linux-gnu/libc.so.6", O_RDONLY|O_CLOEXEC) = 3
  19. 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
  20. 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
  21. 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
  22. 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
  23. newfstatat(3, "", {st_mode=S_IFREG|0755, st_size=2220400, ...}, AT_EMPTY_PATH) = 0
  24. 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
  25. mmap(NULL, 2264656, PROT_READ, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x7f584c200000
  26. mprotect(0x7f584c228000, 2023424, PROT_NONE) = 0
  27. mmap(0x7f584c228000, 1658880, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x28000) = 0x7f584c228000
  28. mmap(0x7f584c3bd000, 360448, PROT_READ, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x1bd000) = 0x7f584c3bd000
  29. mmap(0x7f584c416000, 24576, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x215000) = 0x7f584c416000
  30. mmap(0x7f584c41c000, 52816, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0x7f584c41c000
  31. close(3) = 0
  32. mmap(NULL, 12288, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f584c4b0000
  33. arch_prctl(ARCH_SET_FS, 0x7f584c4b0740) = 0
  34. set_tid_address(0x7f584c4b0a10) = 649416
  35. set_robust_list(0x7f584c4b0a20, 24) = 0
  36. rseq(0x7f584c4b10e0, 0x20, 0, 0x53053053) = 0
  37. mprotect(0x7f584c416000, 16384, PROT_READ) = 0
  38. mprotect(0x7f584c4e0000, 16384, PROT_READ) = 0
  39. mprotect(0x5577b9661000, 16384, PROT_READ) = 0
  40. mprotect(0x7f584c537000, 8192, PROT_READ) = 0
  41. prlimit64(0, RLIMIT_STACK, NULL, {rlim_cur=8192*1024, rlim_max=RLIM64_INFINITY}) = 0
  42. munmap(0x7f584c4e5000, 95179) = 0
  43. openat(AT_FDCWD, "/dev/tty", O_RDWR|O_NONBLOCK) = 3
  44. close(3) = 0
  45. getrandom("\xaf\x8b\x4d\x62\x2c\xae\x8f\x65", 8, GRND_NONBLOCK) = 8
  46. brk(NULL) = 0x5577b9e0f000
  47. brk(0x5577b9e30000) = 0x5577b9e30000
  48. openat(AT_FDCWD, "/usr/lib/locale/locale-archive", O_RDONLY|O_CLOEXEC) = 3
  49. newfstatat(3, "", {st_mode=S_IFREG|0644, st_size=8872448, ...}, AT_EMPTY_PATH) = 0
  50. mmap(NULL, 8872448, PROT_READ, MAP_PRIVATE, 3, 0) = 0x7f584b800000
  51. close(3) = 0
  52. openat(AT_FDCWD, "/usr/lib/x86_64-linux-gnu/gconv/gconv-modules.cache", O_RDONLY) = 3
  53. newfstatat(3, "", {st_mode=S_IFREG|0644, st_size=27002, ...}, AT_EMPTY_PATH) = 0
  54. mmap(NULL, 27002, PROT_READ, MAP_SHARED, 3, 0) = 0x7f584c4f6000
  55. close(3) = 0
  56. futex(0x7f584c41ba6c, FUTEX_WAKE_PRIVATE, 2147483647) = 0
  57. getuid() = 1006
  58. getgid() = 1002
  59. geteuid() = 1006
  60. getegid() = 1002
  61. rt_sigprocmask(SIG_BLOCK, NULL, [], 8) = 0
  62. ioctl(-1, TIOCGPGRP, 0x7fffb1f38dc4) = -1 EBADF (Bad file descriptor)
  63. 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
  64. 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
  65. 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
  66. 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
  67. 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
  68. 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
  69. 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
  70. 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
  71. 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
  72. 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
  73. 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
  74. 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
  75. 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
  76. rt_sigprocmask(SIG_BLOCK, NULL, [], 8) = 0
  77. 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
  78. uname({sysname="Linux", nodename="liubo-SYS-7048GR-TR", ...}) = 0
  79. newfstatat(AT_FDCWD, "/home/zhangchen", {st_mode=S_IFDIR|0750, st_size=4096, ...}, 0) = 0
  80. newfstatat(AT_FDCWD, ".", {st_mode=S_IFDIR|0750, st_size=4096, ...}, 0) = 0
  81. newfstatat(AT_FDCWD, "/home", {st_mode=S_IFDIR|0755, st_size=4096, ...}, 0) = 0
  82. newfstatat(AT_FDCWD, "/home/zhangchen", {st_mode=S_IFDIR|0750, st_size=4096, ...}, 0) = 0
  83. getpid() = 649416
  84. getppid() = 649413
  85. newfstatat(AT_FDCWD, ".", {st_mode=S_IFDIR|0750, st_size=4096, ...}, 0) = 0
  86. 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)
  87. newfstatat(AT_FDCWD, "/home/zhangchen/.conda/envs/DL/bin/bash", 0x7fffb1f38a00, 0) = -1 ENOENT (No such file or directory)
  88. newfstatat(AT_FDCWD, "/opt/miniconda3/condabin/bash", 0x7fffb1f38a00, 0) = -1 ENOENT (No such file or directory)
  89. newfstatat(AT_FDCWD, "/opt/miniconda3/bin/bash", 0x7fffb1f38a00, 0) = -1 ENOENT (No such file or directory)
  90. newfstatat(AT_FDCWD, "/usr/local/sbin/bash", 0x7fffb1f38a00, 0) = -1 ENOENT (No such file or directory)
  91. newfstatat(AT_FDCWD, "/usr/local/bin/bash", 0x7fffb1f38a00, 0) = -1 ENOENT (No such file or directory)
  92. newfstatat(AT_FDCWD, "/usr/sbin/bash", 0x7fffb1f38a00, 0) = -1 ENOENT (No such file or directory)
  93. newfstatat(AT_FDCWD, "/usr/bin/bash", {st_mode=S_IFREG|0755, st_size=1396520, ...}, 0) = 0
  94. newfstatat(AT_FDCWD, "/usr/bin/bash", {st_mode=S_IFREG|0755, st_size=1396520, ...}, 0) = 0
  95. geteuid() = 1006
  96. getegid() = 1002
  97. getuid() = 1006
  98. getgid() = 1002
  99. access("/usr/bin/bash", X_OK) = 0
  100. newfstatat(AT_FDCWD, "/usr/bin/bash", {st_mode=S_IFREG|0755, st_size=1396520, ...}, 0) = 0
  101. geteuid() = 1006
  102. getegid() = 1002
  103. getuid() = 1006
  104. getgid() = 1002
  105. access("/usr/bin/bash", R_OK) = 0
  106. newfstatat(AT_FDCWD, "/usr/bin/bash", {st_mode=S_IFREG|0755, st_size=1396520, ...}, 0) = 0
  107. newfstatat(AT_FDCWD, "/usr/bin/bash", {st_mode=S_IFREG|0755, st_size=1396520, ...}, 0) = 0
  108. geteuid() = 1006
  109. getegid() = 1002
  110. getuid() = 1006
  111. getgid() = 1002
  112. access("/usr/bin/bash", X_OK) = 0
  113. newfstatat(AT_FDCWD, "/usr/bin/bash", {st_mode=S_IFREG|0755, st_size=1396520, ...}, 0) = 0
  114. geteuid() = 1006
  115. getegid() = 1002
  116. getuid() = 1006
  117. getgid() = 1002
  118. access("/usr/bin/bash", R_OK) = 0
  119. getpid() = 649416
  120. getppid() = 649413
  121. getpid() = 649416
  122. getppid() = 649413
  123. getpgrp() = 649413
  124. ioctl(2, TIOCGPGRP, [649413]) = 0
  125. 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
  126. prlimit64(0, RLIMIT_NPROC, NULL, {rlim_cur=514857, rlim_max=514857}) = 0
  127. rt_sigprocmask(SIG_BLOCK, NULL, [], 8) = 0
  128. openat(AT_FDCWD, "test.sh", O_RDONLY) = 3
  129. newfstatat(AT_FDCWD, "test.sh", {st_mode=S_IFREG|0777, st_size=20, ...}, 0) = 0
  130. ioctl(3, TCGETS, 0x7fffb1f38d60) = -1 ENOTTY (Inappropriate ioctl for device)
  131. lseek(3, 0, SEEK_CUR) = 0
  132. read(3, "(sleep 20;sleep 10)\n", 80) = 20
  133. lseek(3, 0, SEEK_SET) = 0
  134. prlimit64(0, RLIMIT_NOFILE, NULL, {rlim_cur=1024*1024, rlim_max=1024*1024}) = 0
  135. fcntl(255, F_GETFD) = -1 EBADF (Bad file descriptor)
  136. dup2(3, 255) = 255
  137. close(3) = 0
  138. fcntl(255, F_SETFD, FD_CLOEXEC) = 0
  139. fcntl(255, F_GETFL) = 0x8000 (flags O_RDONLY|O_LARGEFILE)
  140. newfstatat(255, "", {st_mode=S_IFREG|0777, st_size=20, ...}, AT_EMPTY_PATH) = 0
  141. lseek(255, 0, SEEK_CUR) = 0
  142. read(255, "(sleep 20;sleep 10)\n", 20) = 20
  143. rt_sigprocmask(SIG_BLOCK, NULL, [], 8) = 0
  144. rt_sigprocmask(SIG_BLOCK, [INT TERM CHLD], [], 8) = 0
  145. clone(child_stack=NULL, flags=CLONE_CHILD_CLEARTID|CLONE_CHILD_SETTID|SIGCHLD, child_tidptr=0x7f584c4b0a10) = 649417
  146. strace: Process 649417 attached
  147. [pid 649416] rt_sigprocmask(SIG_SETMASK, [], <unfinished ...>
  148. [pid 649417] set_robust_list(0x7f584c4b0a20, 24 <unfinished ...>
  149. [pid 649416] <... rt_sigprocmask resumed>NULL, 8) = 0
  150. [pid 649417] <... set_robust_list resumed>) = 0
  151. [pid 649416] rt_sigprocmask(SIG_BLOCK, [CHLD], [], 8) = 0
  152. [pid 649416] rt_sigprocmask(SIG_SETMASK, [], <unfinished ...>
  153. [pid 649417] getpid( <unfinished ...>
  154. [pid 649416] <... rt_sigprocmask resumed>NULL, 8) = 0
  155. [pid 649417] <... getpid resumed>) = 649417
  156. [pid 649416] rt_sigprocmask(SIG_BLOCK, [CHLD], [], 8) = 0
  157. [pid 649416] rt_sigaction(SIGINT, {sa_handler=0x5577b9578dc0, sa_mask=[], sa_flags=SA_RESTORER, sa_restorer=0x7f584c242520}, <unfinished ...>
  158. [pid 649417] close(255 <unfinished ...>
  159. [pid 649416] <... rt_sigaction resumed>{sa_handler=SIG_DFL, sa_mask=[], sa_flags=SA_RESTORER, sa_restorer=0x7f584c242520}, 8) = 0
  160. [pid 649417] <... close resumed>) = 0
  161. [pid 649416] wait4(-1, <unfinished ...>
  162. [pid 649417] rt_sigprocmask(SIG_SETMASK, [], NULL, 8) = 0
  163. [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
  164. [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
  165. [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
  166. [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
  167. [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
  168. [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
  169. [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
  170. [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
  171. [pid 649417] rt_sigprocmask(SIG_BLOCK, [CHLD], [], 8) = 0
  172. [pid 649417] rt_sigprocmask(SIG_SETMASK, [], NULL, 8) = 0
  173. [pid 649417] newfstatat(AT_FDCWD, ".", {st_mode=S_IFDIR|0750, st_size=4096, ...}, 0) = 0
  174. [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)
  175. [pid 649417] newfstatat(AT_FDCWD, "/home/zhangchen/.conda/envs/DL/bin/sleep", 0x7fffb1f385a0, 0) = -1 ENOENT (No such file or directory)
  176. [pid 649417] newfstatat(AT_FDCWD, "/opt/miniconda3/condabin/sleep", 0x7fffb1f385a0, 0) = -1 ENOENT (No such file or directory)
  177. [pid 649417] newfstatat(AT_FDCWD, "/opt/miniconda3/bin/sleep", 0x7fffb1f385a0, 0) = -1 ENOENT (No such file or directory)
  178. [pid 649417] newfstatat(AT_FDCWD, "/usr/local/sbin/sleep", 0x7fffb1f385a0, 0) = -1 ENOENT (No such file or directory)
  179. [pid 649417] newfstatat(AT_FDCWD, "/usr/local/bin/sleep", 0x7fffb1f385a0, 0) = -1 ENOENT (No such file or directory)
  180. [pid 649417] newfstatat(AT_FDCWD, "/usr/sbin/sleep", 0x7fffb1f385a0, 0) = -1 ENOENT (No such file or directory)
  181. [pid 649417] newfstatat(AT_FDCWD, "/usr/bin/sleep", {st_mode=S_IFREG|0755, st_size=35328, ...}, 0) = 0
  182. [pid 649417] newfstatat(AT_FDCWD, "/usr/bin/sleep", {st_mode=S_IFREG|0755, st_size=35328, ...}, 0) = 0
  183. [pid 649417] geteuid() = 1006
  184. [pid 649417] getegid() = 1002
  185. [pid 649417] getuid() = 1006
  186. [pid 649417] getgid() = 1002
  187. [pid 649417] access("/usr/bin/sleep", X_OK) = 0
  188. [pid 649417] newfstatat(AT_FDCWD, "/usr/bin/sleep", {st_mode=S_IFREG|0755, st_size=35328, ...}, 0) = 0
  189. [pid 649417] geteuid() = 1006
  190. [pid 649417] getegid() = 1002
  191. [pid 649417] getuid() = 1006
  192. [pid 649417] getgid() = 1002
  193. [pid 649417] access("/usr/bin/sleep", R_OK) = 0
  194. [pid 649417] newfstatat(AT_FDCWD, "/usr/bin/sleep", {st_mode=S_IFREG|0755, st_size=35328, ...}, 0) = 0
  195. [pid 649417] newfstatat(AT_FDCWD, "/usr/bin/sleep", {st_mode=S_IFREG|0755, st_size=35328, ...}, 0) = 0
  196. [pid 649417] geteuid() = 1006
  197. [pid 649417] getegid() = 1002
  198. [pid 649417] getuid() = 1006
  199. [pid 649417] getgid() = 1002
  200. [pid 649417] access("/usr/bin/sleep", X_OK) = 0
  201. [pid 649417] newfstatat(AT_FDCWD, "/usr/bin/sleep", {st_mode=S_IFREG|0755, st_size=35328, ...}, 0) = 0
  202. [pid 649417] geteuid() = 1006
  203. [pid 649417] getegid() = 1002
  204. [pid 649417] getuid() = 1006
  205. [pid 649417] getgid() = 1002
  206. [pid 649417] access("/usr/bin/sleep", R_OK) = 0
  207. [pid 649417] rt_sigprocmask(SIG_BLOCK, NULL, [], 8) = 0
  208. [pid 649417] rt_sigprocmask(SIG_BLOCK, [INT TERM CHLD], [], 8) = 0
  209. [pid 649417] clone(child_stack=NULL, flags=CLONE_CHILD_CLEARTID|CLONE_CHILD_SETTID|SIGCHLD, child_tidptr=0x7f584c4b0a10) = 649418
  210. strace: Process 649418 attached
  211. [pid 649417] rt_sigprocmask(SIG_SETMASK, [], <unfinished ...>
  212. [pid 649418] set_robust_list(0x7f584c4b0a20, 24 <unfinished ...>
  213. [pid 649417] <... rt_sigprocmask resumed>NULL, 8) = 0
  214. [pid 649418] <... set_robust_list resumed>) = 0
  215. [pid 649417] rt_sigprocmask(SIG_BLOCK, [CHLD], <unfinished ...>
  216. [pid 649418] getpid( <unfinished ...>
  217. [pid 649417] <... rt_sigprocmask resumed>[], 8) = 0
  218. [pid 649418] <... getpid resumed>) = 649418
  219. [pid 649417] rt_sigprocmask(SIG_SETMASK, [], <unfinished ...>
  220. [pid 649418] rt_sigprocmask(SIG_SETMASK, [], <unfinished ...>
  221. [pid 649417] <... rt_sigprocmask resumed>NULL, 8) = 0
  222. [pid 649418] <... rt_sigprocmask resumed>NULL, 8) = 0
  223. [pid 649417] rt_sigprocmask(SIG_BLOCK, [CHLD], <unfinished ...>
  224. [pid 649418] rt_sigaction(SIGTSTP, {sa_handler=SIG_DFL, sa_mask=[], sa_flags=SA_RESTORER, sa_restorer=0x7f584c242520}, <unfinished ...>
  225. [pid 649417] <... rt_sigprocmask resumed>[], 8) = 0
  226. [pid 649418] <... rt_sigaction resumed>{sa_handler=SIG_DFL, sa_mask=[], sa_flags=SA_RESTORER, sa_restorer=0x7f584c242520}, 8) = 0
  227. [pid 649417] rt_sigaction(SIGINT, {sa_handler=0x5577b9578dc0, sa_mask=[], sa_flags=SA_RESTORER, sa_restorer=0x7f584c242520}, <unfinished ...>
  228. [pid 649418] rt_sigaction(SIGTTIN, {sa_handler=SIG_DFL, sa_mask=[], sa_flags=SA_RESTORER, sa_restorer=0x7f584c242520}, <unfinished ...>
  229. [pid 649417] <... rt_sigaction resumed>{sa_handler=0x5577b95a3410, sa_mask=[], sa_flags=SA_RESTORER, sa_restorer=0x7f584c242520}, 8) = 0
  230. [pid 649418] <... rt_sigaction resumed>{sa_handler=SIG_DFL, sa_mask=[], sa_flags=SA_RESTORER, sa_restorer=0x7f584c242520}, 8) = 0
  231. [pid 649417] wait4(-1, <unfinished ...>
  232. [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
  233. [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
  234. [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
  235. [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
  236. [pid 649418] execve("/usr/bin/sleep", ["sleep", "20"], 0x5577b9e20b60 /* 54 vars */) = 0
  237. [pid 649418] brk(NULL) = 0x5561fa911000
  238. [pid 649418] arch_prctl(0x3001 /* ARCH_??? */, 0x7ffc69f99ce0) = -1 EINVAL (Invalid argument)
  239. [pid 649418] mmap(NULL, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f554a9ee000
  240. [pid 649418] access("/etc/ld.so.preload", R_OK) = -1 ENOENT (No such file or directory)
  241. [pid 649418] openat(AT_FDCWD, "/etc/ld.so.cache", O_RDONLY|O_CLOEXEC) = 3
  242. [pid 649418] newfstatat(3, "", {st_mode=S_IFREG|0644, st_size=95179, ...}, AT_EMPTY_PATH) = 0
  243. [pid 649418] mmap(NULL, 95179, PROT_READ, MAP_PRIVATE, 3, 0) = 0x7f554a9d6000
  244. [pid 649418] close(3) = 0
  245. [pid 649418] openat(AT_FDCWD, "/lib/x86_64-linux-gnu/libc.so.6", O_RDONLY|O_CLOEXEC) = 3
  246. [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
  247. [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
  248. [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
  249. [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
  250. [pid 649418] newfstatat(3, "", {st_mode=S_IFREG|0755, st_size=2220400, ...}, AT_EMPTY_PATH) = 0
  251. [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
  252. [pid 649418] mmap(NULL, 2264656, PROT_READ, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x7f554a600000
  253. [pid 649418] mprotect(0x7f554a628000, 2023424, PROT_NONE) = 0
  254. [pid 649418] mmap(0x7f554a628000, 1658880, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x28000) = 0x7f554a628000
  255. [pid 649418] mmap(0x7f554a7bd000, 360448, PROT_READ, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x1bd000) = 0x7f554a7bd000
  256. [pid 649418] mmap(0x7f554a816000, 24576, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x215000) = 0x7f554a816000
  257. [pid 649418] mmap(0x7f554a81c000, 52816, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0x7f554a81c000
  258. [pid 649418] close(3) = 0
  259. [pid 649418] mmap(NULL, 12288, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f554a9d3000
  260. [pid 649418] arch_prctl(ARCH_SET_FS, 0x7f554a9d3740) = 0
  261. [pid 649418] set_tid_address(0x7f554a9d3a10) = 649418
  262. [pid 649418] set_robust_list(0x7f554a9d3a20, 24) = 0
  263. [pid 649418] rseq(0x7f554a9d40e0, 0x20, 0, 0x53053053) = 0
  264. [pid 649418] mprotect(0x7f554a816000, 16384, PROT_READ) = 0
  265. [pid 649418] mprotect(0x5561f8e6f000, 4096, PROT_READ) = 0
  266. [pid 649418] mprotect(0x7f554aa28000, 8192, PROT_READ) = 0
  267. [pid 649418] prlimit64(0, RLIMIT_STACK, NULL, {rlim_cur=8192*1024, rlim_max=RLIM64_INFINITY}) = 0
  268. [pid 649418] munmap(0x7f554a9d6000, 95179) = 0
  269. [pid 649418] getrandom("\xe2\xdf\xc1\x0c\x9a\xb3\xb1\x8c", 8, GRND_NONBLOCK) = 8
  270. [pid 649418] brk(NULL) = 0x5561fa911000
  271. [pid 649418] brk(0x5561fa932000) = 0x5561fa932000
  272. [pid 649418] openat(AT_FDCWD, "/usr/lib/locale/locale-archive", O_RDONLY|O_CLOEXEC) = 3
  273. [pid 649418] newfstatat(3, "", {st_mode=S_IFREG|0644, st_size=8872448, ...}, AT_EMPTY_PATH) = 0
  274. [pid 649418] mmap(NULL, 8872448, PROT_READ, MAP_PRIVATE, 3, 0) = 0x7f5549c00000
  275. [pid 649418] close(3) = 0
  276. [pid 649418] clock_nanosleep(CLOCK_REALTIME, 0, {tv_sec=20, tv_nsec=0}, 0x7ffc69f99d30) = 0
  277. [pid 649418] close(1) = 0
  278. [pid 649418] close(2) = 0
  279. [pid 649418] exit_group(0) = ?
  280. [pid 649418] +++ exited with 0 +++
  281. [pid 649417] <... wait4 resumed>[{WIFEXITED(s) && WEXITSTATUS(s) == 0}], 0, NULL) = 649418
  282. [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
  283. [pid 649417] rt_sigprocmask(SIG_SETMASK, [], NULL, 8) = 0
  284. [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} ---
  285. [pid 649417] wait4(-1, 0x7fffb1f38050, WNOHANG, NULL) = -1 ECHILD (No child processes)
  286. [pid 649417] rt_sigreturn({mask=[]}) = 0
  287. [pid 649417] rt_sigprocmask(SIG_BLOCK, NULL, [], 8) = 0
  288. [pid 649417] rt_sigprocmask(SIG_BLOCK, [INT TERM CHLD], [], 8) = 0
  289. [pid 649417] clone(child_stack=NULL, flags=CLONE_CHILD_CLEARTID|CLONE_CHILD_SETTID|SIGCHLD, child_tidptr=0x7f584c4b0a10) = 649682
  290. strace: Process 649682 attached
  291. [pid 649417] rt_sigprocmask(SIG_SETMASK, [], NULL, 8) = 0
  292. [pid 649682] set_robust_list(0x7f584c4b0a20, 24) = 0
  293. [pid 649417] rt_sigprocmask(SIG_BLOCK, [CHLD], [], 8) = 0
  294. [pid 649682] getpid( <unfinished ...>
  295. [pid 649417] rt_sigprocmask(SIG_SETMASK, [], <unfinished ...>
  296. [pid 649682] <... getpid resumed>) = 649682
  297. [pid 649417] <... rt_sigprocmask resumed>NULL, 8) = 0
  298. [pid 649682] rt_sigprocmask(SIG_SETMASK, [], <unfinished ...>
  299. [pid 649417] rt_sigprocmask(SIG_BLOCK, [CHLD], <unfinished ...>
  300. [pid 649682] <... rt_sigprocmask resumed>NULL, 8) = 0
  301. [pid 649417] <... rt_sigprocmask resumed>[], 8) = 0
  302. [pid 649682] rt_sigaction(SIGTSTP, {sa_handler=SIG_DFL, sa_mask=[], sa_flags=SA_RESTORER, sa_restorer=0x7f584c242520}, <unfinished ...>
  303. [pid 649417] rt_sigaction(SIGINT, {sa_handler=0x5577b9578dc0, sa_mask=[], sa_flags=SA_RESTORER, sa_restorer=0x7f584c242520}, <unfinished ...>
  304. [pid 649682] <... rt_sigaction resumed>{sa_handler=SIG_DFL, sa_mask=[], sa_flags=SA_RESTORER, sa_restorer=0x7f584c242520}, 8) = 0
  305. [pid 649417] <... rt_sigaction resumed>{sa_handler=0x5577b95a3410, sa_mask=[], sa_flags=SA_RESTORER, sa_restorer=0x7f584c242520}, 8) = 0
  306. [pid 649682] rt_sigaction(SIGTTIN, {sa_handler=SIG_DFL, sa_mask=[], sa_flags=SA_RESTORER, sa_restorer=0x7f584c242520}, <unfinished ...>
  307. [pid 649417] wait4(-1, <unfinished ...>
  308. [pid 649682] <... rt_sigaction resumed>{sa_handler=SIG_DFL, sa_mask=[], sa_flags=SA_RESTORER, sa_restorer=0x7f584c242520}, 8) = 0
  309. [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
  310. [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
  311. [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
  312. [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
  313. [pid 649682] execve("/usr/bin/sleep", ["sleep", "10"], 0x5577b9e20b60 /* 54 vars */) = 0
  314. [pid 649682] brk(NULL) = 0x5591174fc000
  315. [pid 649682] arch_prctl(0x3001 /* ARCH_??? */, 0x7fffce0decd0) = -1 EINVAL (Invalid argument)
  316. [pid 649682] mmap(NULL, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f6113dd6000
  317. [pid 649682] access("/etc/ld.so.preload", R_OK) = -1 ENOENT (No such file or directory)
  318. [pid 649682] openat(AT_FDCWD, "/etc/ld.so.cache", O_RDONLY|O_CLOEXEC) = 3
  319. [pid 649682] newfstatat(3, "", {st_mode=S_IFREG|0644, st_size=95179, ...}, AT_EMPTY_PATH) = 0
  320. [pid 649682] mmap(NULL, 95179, PROT_READ, MAP_PRIVATE, 3, 0) = 0x7f6113dbe000
  321. [pid 649682] close(3) = 0
  322. [pid 649682] openat(AT_FDCWD, "/lib/x86_64-linux-gnu/libc.so.6", O_RDONLY|O_CLOEXEC) = 3
  323. [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
  324. [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
  325. [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
  326. [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
  327. [pid 649682] newfstatat(3, "", {st_mode=S_IFREG|0755, st_size=2220400, ...}, AT_EMPTY_PATH) = 0
  328. [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
  329. [pid 649682] mmap(NULL, 2264656, PROT_READ, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x7f6113a00000
  330. [pid 649682] mprotect(0x7f6113a28000, 2023424, PROT_NONE) = 0
  331. [pid 649682] mmap(0x7f6113a28000, 1658880, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x28000) = 0x7f6113a28000
  332. [pid 649682] mmap(0x7f6113bbd000, 360448, PROT_READ, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x1bd000) = 0x7f6113bbd000
  333. [pid 649682] mmap(0x7f6113c16000, 24576, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x215000) = 0x7f6113c16000
  334. [pid 649682] mmap(0x7f6113c1c000, 52816, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0x7f6113c1c000
  335. [pid 649682] close(3) = 0
  336. [pid 649682] mmap(NULL, 12288, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f6113dbb000
  337. [pid 649682] arch_prctl(ARCH_SET_FS, 0x7f6113dbb740) = 0
  338. [pid 649682] set_tid_address(0x7f6113dbba10) = 649682
  339. [pid 649682] set_robust_list(0x7f6113dbba20, 24) = 0
  340. [pid 649682] rseq(0x7f6113dbc0e0, 0x20, 0, 0x53053053) = 0
  341. [pid 649682] mprotect(0x7f6113c16000, 16384, PROT_READ) = 0
  342. [pid 649682] mprotect(0x5591162b5000, 4096, PROT_READ) = 0
  343. [pid 649682] mprotect(0x7f6113e10000, 8192, PROT_READ) = 0
  344. [pid 649682] prlimit64(0, RLIMIT_STACK, NULL, {rlim_cur=8192*1024, rlim_max=RLIM64_INFINITY}) = 0
  345. [pid 649682] munmap(0x7f6113dbe000, 95179) = 0
  346. [pid 649682] getrandom("\x76\xed\x66\x62\x5c\xcf\x79\x1b", 8, GRND_NONBLOCK) = 8
  347. [pid 649682] brk(NULL) = 0x5591174fc000
  348. [pid 649682] brk(0x55911751d000) = 0x55911751d000
  349. [pid 649682] openat(AT_FDCWD, "/usr/lib/locale/locale-archive", O_RDONLY|O_CLOEXEC) = 3
  350. [pid 649682] newfstatat(3, "", {st_mode=S_IFREG|0644, st_size=8872448, ...}, AT_EMPTY_PATH) = 0
  351. [pid 649682] mmap(NULL, 8872448, PROT_READ, MAP_PRIVATE, 3, 0) = 0x7f6113000000
  352. [pid 649682] close(3) = 0
  353. [pid 649682] clock_nanosleep(CLOCK_REALTIME, 0, {tv_sec=10, tv_nsec=0}, 0x7fffce0ded20) = 0
  354. [pid 649682] close(1) = 0
  355. [pid 649682] close(2) = 0
  356. [pid 649682] exit_group(0) = ?
  357. [pid 649682] +++ exited with 0 +++
  358. [pid 649417] <... wait4 resumed>[{WIFEXITED(s) && WEXITSTATUS(s) == 0}], 0, NULL) = 649682
  359. [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
  360. [pid 649417] rt_sigprocmask(SIG_SETMASK, [], NULL, 8) = 0
  361. [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} ---
  362. [pid 649417] wait4(-1, 0x7fffb1f38090, WNOHANG, NULL) = -1 ECHILD (No child processes)
  363. [pid 649417] rt_sigreturn({mask=[]}) = 0
  364. [pid 649417] exit_group(0) = ?
  365. [pid 649417] +++ exited with 0 +++
  366. <... wait4 resumed>[{WIFEXITED(s) && WEXITSTATUS(s) == 0}], 0, NULL) = 649417
  367. 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
  368. ioctl(2, TIOCGWINSZ, {ws_row=21, ws_col=200, ws_xpixel=0, ws_ypixel=0}) = 0
  369. ioctl(1, TCGETS, {B38400 opost isig icanon echo ...}) = 0
  370. getuid() = 1006
  371. geteuid() = 1006
  372. getgid() = 1002
  373. getegid() = 1002
  374. getuid() = 1006
  375. geteuid() = 1006
  376. getgid() = 1002
  377. getegid() = 1002
  378. newfstatat(AT_FDCWD, "/home/zhangchen/.terminfo", 0x5577b9e26460, 0) = -1 ENOENT (No such file or directory)
  379. newfstatat(AT_FDCWD, "/etc/terminfo", {st_mode=S_IFDIR|0755, st_size=4096, ...}, 0) = 0
  380. newfstatat(AT_FDCWD, "/lib/terminfo", {st_mode=S_IFDIR|0755, st_size=4096, ...}, 0) = 0
  381. newfstatat(AT_FDCWD, "/usr/share/terminfo", {st_mode=S_IFDIR|0755, st_size=4096, ...}, 0) = 0
  382. access("/etc/terminfo/x/xterm-256color", R_OK) = -1 ENOENT (No such file or directory)
  383. access("/lib/terminfo/x/xterm-256color", R_OK) = 0
  384. openat(AT_FDCWD, "/lib/terminfo/x/xterm-256color", O_RDONLY) = 3
  385. newfstatat(3, "", {st_mode=S_IFREG|0644, st_size=3852, ...}, AT_EMPTY_PATH) = 0
  386. read(3, "\36\2%\0&\0\17\0\235\1Z\6xterm-256color|xterm"..., 32768) = 3852
  387. read(3, "", 28672) = 0
  388. close(3) = 0
  389. ioctl(1, TCGETS, {B38400 opost isig icanon echo ...}) = 0
  390. ioctl(1, TCGETS, {B38400 opost isig icanon echo ...}) = 0
  391. ioctl(1, TCGETS, {B38400 opost isig icanon echo ...}) = 0
  392. ioctl(1, TCGETS, {B38400 opost isig icanon echo ...}) = 0
  393. ioctl(1, TIOCGWINSZ, {ws_row=21, ws_col=200, ws_xpixel=0, ws_ypixel=0}) = 0
  394. ioctl(0, TIOCGWINSZ, {ws_row=21, ws_col=200, ws_xpixel=0, ws_ypixel=0}) = 0
  395. brk(0x5577b9e51000) = 0x5577b9e51000
  396. rt_sigprocmask(SIG_SETMASK, [], NULL, 8) = 0
  397. --- SIGCHLD {si_signo=SIGCHLD, si_code=CLD_EXITED, si_pid=649417, si_uid=1006, si_status=0, si_utime=0, si_stime=0} ---
  398. wait4(-1, 0x7fffb1f38310, WNOHANG, NULL) = -1 ECHILD (No child processes)
  399. rt_sigreturn({mask=[]}) = 0
  400. read(255, "", 20) = 0
  401. rt_sigprocmask(SIG_BLOCK, [CHLD], [], 8) = 0
  402. rt_sigprocmask(SIG_SETMASK, [], NULL, 8) = 0
  403. exit_group(0) = ?
  404. +++ 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进程结束后才能观察到。

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

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

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

  1. # 文件test.sh
  2. (sleep 20)

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

  1. execve("/usr/bin/bash", ["bash", "test.sh"], 0x7fff4735b310 /* 55 vars */) = 0
  2. brk(NULL) = 0x55611d9ff000
  3. arch_prctl(0x3001 /* ARCH_??? */, 0x7fff55dc2db0) = -1 EINVAL (Invalid argument)
  4. mmap(NULL, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fd7fcc46000
  5. access("/etc/ld.so.preload", R_OK) = -1 ENOENT (No such file or directory)
  6. openat(AT_FDCWD, "/etc/ld.so.cache", O_RDONLY|O_CLOEXEC) = 3
  7. newfstatat(3, "", {st_mode=S_IFREG|0644, st_size=95179, ...}, AT_EMPTY_PATH) = 0
  8. mmap(NULL, 95179, PROT_READ, MAP_PRIVATE, 3, 0) = 0x7fd7fcc2e000
  9. close(3) = 0
  10. openat(AT_FDCWD, "/lib/x86_64-linux-gnu/libtinfo.so.6", O_RDONLY|O_CLOEXEC) = 3
  11. 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
  12. newfstatat(3, "", {st_mode=S_IFREG|0644, st_size=200136, ...}, AT_EMPTY_PATH) = 0
  13. mmap(NULL, 203040, PROT_READ, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x7fd7fcbfc000
  14. mmap(0x7fd7fcc0a000, 69632, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0xe000) = 0x7fd7fcc0a000
  15. mmap(0x7fd7fcc1b000, 57344, PROT_READ, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x1f000) = 0x7fd7fcc1b000
  16. mmap(0x7fd7fcc29000, 20480, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x2c000) = 0x7fd7fcc29000
  17. close(3) = 0
  18. openat(AT_FDCWD, "/lib/x86_64-linux-gnu/libc.so.6", O_RDONLY|O_CLOEXEC) = 3
  19. 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
  20. 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
  21. 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
  22. 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
  23. newfstatat(3, "", {st_mode=S_IFREG|0755, st_size=2220400, ...}, AT_EMPTY_PATH) = 0
  24. 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
  25. mmap(NULL, 2264656, PROT_READ, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x7fd7fc800000
  26. mprotect(0x7fd7fc828000, 2023424, PROT_NONE) = 0
  27. mmap(0x7fd7fc828000, 1658880, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x28000) = 0x7fd7fc828000
  28. mmap(0x7fd7fc9bd000, 360448, PROT_READ, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x1bd000) = 0x7fd7fc9bd000
  29. mmap(0x7fd7fca16000, 24576, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x215000) = 0x7fd7fca16000
  30. mmap(0x7fd7fca1c000, 52816, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0x7fd7fca1c000
  31. close(3) = 0
  32. mmap(NULL, 12288, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fd7fcbf9000
  33. arch_prctl(ARCH_SET_FS, 0x7fd7fcbf9740) = 0
  34. set_tid_address(0x7fd7fcbf9a10) = 661035
  35. set_robust_list(0x7fd7fcbf9a20, 24) = 0
  36. rseq(0x7fd7fcbfa0e0, 0x20, 0, 0x53053053) = 0
  37. mprotect(0x7fd7fca16000, 16384, PROT_READ) = 0
  38. mprotect(0x7fd7fcc29000, 16384, PROT_READ) = 0
  39. mprotect(0x55611c4a1000, 16384, PROT_READ) = 0
  40. mprotect(0x7fd7fcc80000, 8192, PROT_READ) = 0
  41. prlimit64(0, RLIMIT_STACK, NULL, {rlim_cur=8192*1024, rlim_max=RLIM64_INFINITY}) = 0
  42. munmap(0x7fd7fcc2e000, 95179) = 0
  43. openat(AT_FDCWD, "/dev/tty", O_RDWR|O_NONBLOCK) = 3
  44. close(3) = 0
  45. getrandom("\x1b\x51\x8d\x2a\xb7\x02\xc5\xd7", 8, GRND_NONBLOCK) = 8
  46. brk(NULL) = 0x55611d9ff000
  47. brk(0x55611da20000) = 0x55611da20000
  48. openat(AT_FDCWD, "/usr/lib/locale/locale-archive", O_RDONLY|O_CLOEXEC) = 3
  49. newfstatat(3, "", {st_mode=S_IFREG|0644, st_size=8872448, ...}, AT_EMPTY_PATH) = 0
  50. mmap(NULL, 8872448, PROT_READ, MAP_PRIVATE, 3, 0) = 0x7fd7fbe00000
  51. close(3) = 0
  52. openat(AT_FDCWD, "/usr/lib/x86_64-linux-gnu/gconv/gconv-modules.cache", O_RDONLY) = 3
  53. newfstatat(3, "", {st_mode=S_IFREG|0644, st_size=27002, ...}, AT_EMPTY_PATH) = 0
  54. mmap(NULL, 27002, PROT_READ, MAP_SHARED, 3, 0) = 0x7fd7fcc3f000
  55. close(3) = 0
  56. futex(0x7fd7fca1ba6c, FUTEX_WAKE_PRIVATE, 2147483647) = 0
  57. getuid() = 1006
  58. getgid() = 1002
  59. geteuid() = 1006
  60. getegid() = 1002
  61. rt_sigprocmask(SIG_BLOCK, NULL, [], 8) = 0
  62. ioctl(-1, TIOCGPGRP, 0x7fff55dc2ca4) = -1 EBADF (Bad file descriptor)
  63. 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
  64. 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
  65. 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
  66. 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
  67. 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
  68. 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
  69. 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
  70. 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
  71. 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
  72. 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
  73. 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
  74. 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
  75. 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
  76. rt_sigprocmask(SIG_BLOCK, NULL, [], 8) = 0
  77. 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
  78. uname({sysname="Linux", nodename="liubo-SYS-7048GR-TR", ...}) = 0
  79. newfstatat(AT_FDCWD, "/home/zhangchen", {st_mode=S_IFDIR|0750, st_size=4096, ...}, 0) = 0
  80. newfstatat(AT_FDCWD, ".", {st_mode=S_IFDIR|0750, st_size=4096, ...}, 0) = 0
  81. newfstatat(AT_FDCWD, "/home", {st_mode=S_IFDIR|0755, st_size=4096, ...}, 0) = 0
  82. newfstatat(AT_FDCWD, "/home/zhangchen", {st_mode=S_IFDIR|0750, st_size=4096, ...}, 0) = 0
  83. getpid() = 661035
  84. getppid() = 661032
  85. newfstatat(AT_FDCWD, ".", {st_mode=S_IFDIR|0750, st_size=4096, ...}, 0) = 0
  86. 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)
  87. newfstatat(AT_FDCWD, "/home/zhangchen/.conda/envs/DL/bin/bash", 0x7fff55dc28e0, 0) = -1 ENOENT (No such file or directory)
  88. newfstatat(AT_FDCWD, "/opt/miniconda3/condabin/bash", 0x7fff55dc28e0, 0) = -1 ENOENT (No such file or directory)
  89. newfstatat(AT_FDCWD, "/opt/miniconda3/bin/bash", 0x7fff55dc28e0, 0) = -1 ENOENT (No such file or directory)
  90. newfstatat(AT_FDCWD, "/usr/local/sbin/bash", 0x7fff55dc28e0, 0) = -1 ENOENT (No such file or directory)
  91. newfstatat(AT_FDCWD, "/usr/local/bin/bash", 0x7fff55dc28e0, 0) = -1 ENOENT (No such file or directory)
  92. newfstatat(AT_FDCWD, "/usr/sbin/bash", 0x7fff55dc28e0, 0) = -1 ENOENT (No such file or directory)
  93. newfstatat(AT_FDCWD, "/usr/bin/bash", {st_mode=S_IFREG|0755, st_size=1396520, ...}, 0) = 0
  94. newfstatat(AT_FDCWD, "/usr/bin/bash", {st_mode=S_IFREG|0755, st_size=1396520, ...}, 0) = 0
  95. geteuid() = 1006
  96. getegid() = 1002
  97. getuid() = 1006
  98. getgid() = 1002
  99. access("/usr/bin/bash", X_OK) = 0
  100. newfstatat(AT_FDCWD, "/usr/bin/bash", {st_mode=S_IFREG|0755, st_size=1396520, ...}, 0) = 0
  101. geteuid() = 1006
  102. getegid() = 1002
  103. getuid() = 1006
  104. getgid() = 1002
  105. access("/usr/bin/bash", R_OK) = 0
  106. newfstatat(AT_FDCWD, "/usr/bin/bash", {st_mode=S_IFREG|0755, st_size=1396520, ...}, 0) = 0
  107. newfstatat(AT_FDCWD, "/usr/bin/bash", {st_mode=S_IFREG|0755, st_size=1396520, ...}, 0) = 0
  108. geteuid() = 1006
  109. getegid() = 1002
  110. getuid() = 1006
  111. getgid() = 1002
  112. access("/usr/bin/bash", X_OK) = 0
  113. newfstatat(AT_FDCWD, "/usr/bin/bash", {st_mode=S_IFREG|0755, st_size=1396520, ...}, 0) = 0
  114. geteuid() = 1006
  115. getegid() = 1002
  116. getuid() = 1006
  117. getgid() = 1002
  118. access("/usr/bin/bash", R_OK) = 0
  119. getpid() = 661035
  120. getppid() = 661032
  121. getpid() = 661035
  122. getppid() = 661032
  123. getpgrp() = 661032
  124. ioctl(2, TIOCGPGRP, [661032]) = 0
  125. 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
  126. prlimit64(0, RLIMIT_NPROC, NULL, {rlim_cur=514857, rlim_max=514857}) = 0
  127. rt_sigprocmask(SIG_BLOCK, NULL, [], 8) = 0
  128. openat(AT_FDCWD, "test.sh", O_RDONLY) = 3
  129. newfstatat(AT_FDCWD, "test.sh", {st_mode=S_IFREG|0777, st_size=11, ...}, 0) = 0
  130. ioctl(3, TCGETS, 0x7fff55dc2c40) = -1 ENOTTY (Inappropriate ioctl for device)
  131. lseek(3, 0, SEEK_CUR) = 0
  132. read(3, "(sleep 20)\n", 80) = 11
  133. lseek(3, 0, SEEK_SET) = 0
  134. prlimit64(0, RLIMIT_NOFILE, NULL, {rlim_cur=1024*1024, rlim_max=1024*1024}) = 0
  135. fcntl(255, F_GETFD) = -1 EBADF (Bad file descriptor)
  136. dup2(3, 255) = 255
  137. close(3) = 0
  138. fcntl(255, F_SETFD, FD_CLOEXEC) = 0
  139. fcntl(255, F_GETFL) = 0x8000 (flags O_RDONLY|O_LARGEFILE)
  140. newfstatat(255, "", {st_mode=S_IFREG|0777, st_size=11, ...}, AT_EMPTY_PATH) = 0
  141. lseek(255, 0, SEEK_CUR) = 0
  142. read(255, "(sleep 20)\n", 11) = 11
  143. rt_sigprocmask(SIG_BLOCK, NULL, [], 8) = 0
  144. rt_sigprocmask(SIG_BLOCK, [INT TERM CHLD], [], 8) = 0
  145. clone(child_stack=NULL, flags=CLONE_CHILD_CLEARTID|CLONE_CHILD_SETTID|SIGCHLD, child_tidptr=0x7fd7fcbf9a10) = 661036
  146. strace: Process 661036 attached
  147. [pid 661035] rt_sigprocmask(SIG_SETMASK, [], NULL, 8) = 0
  148. [pid 661035] rt_sigprocmask(SIG_BLOCK, [CHLD], [], 8) = 0
  149. [pid 661036] set_robust_list(0x7fd7fcbf9a20, 24 <unfinished ...>
  150. [pid 661035] rt_sigprocmask(SIG_SETMASK, [], <unfinished ...>
  151. [pid 661036] <... set_robust_list resumed>) = 0
  152. [pid 661035] <... rt_sigprocmask resumed>NULL, 8) = 0
  153. [pid 661035] rt_sigprocmask(SIG_BLOCK, [CHLD], [], 8) = 0
  154. [pid 661036] getpid( <unfinished ...>
  155. [pid 661035] rt_sigaction(SIGINT, {sa_handler=0x55611c3b8dc0, sa_mask=[], sa_flags=SA_RESTORER, sa_restorer=0x7fd7fc842520}, <unfinished ...>
  156. [pid 661036] <... getpid resumed>) = 661036
  157. [pid 661035] <... rt_sigaction resumed>{sa_handler=SIG_DFL, sa_mask=[], sa_flags=SA_RESTORER, sa_restorer=0x7fd7fc842520}, 8) = 0
  158. [pid 661035] wait4(-1, <unfinished ...>
  159. [pid 661036] close(255) = 0
  160. [pid 661036] rt_sigprocmask(SIG_SETMASK, [], NULL, 8) = 0
  161. [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
  162. [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
  163. [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
  164. [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
  165. [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
  166. [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
  167. [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
  168. [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
  169. [pid 661036] rt_sigprocmask(SIG_BLOCK, [CHLD], [], 8) = 0
  170. [pid 661036] rt_sigprocmask(SIG_SETMASK, [], NULL, 8) = 0
  171. [pid 661036] newfstatat(AT_FDCWD, ".", {st_mode=S_IFDIR|0750, st_size=4096, ...}, 0) = 0
  172. [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)
  173. [pid 661036] newfstatat(AT_FDCWD, "/home/zhangchen/.conda/envs/DL/bin/sleep", 0x7fff55dc25c0, 0) = -1 ENOENT (No such file or directory)
  174. [pid 661036] newfstatat(AT_FDCWD, "/opt/miniconda3/condabin/sleep", 0x7fff55dc25c0, 0) = -1 ENOENT (No such file or directory)
  175. [pid 661036] newfstatat(AT_FDCWD, "/opt/miniconda3/bin/sleep", 0x7fff55dc25c0, 0) = -1 ENOENT (No such file or directory)
  176. [pid 661036] newfstatat(AT_FDCWD, "/usr/local/sbin/sleep", 0x7fff55dc25c0, 0) = -1 ENOENT (No such file or directory)
  177. [pid 661036] newfstatat(AT_FDCWD, "/usr/local/bin/sleep", 0x7fff55dc25c0, 0) = -1 ENOENT (No such file or directory)
  178. [pid 661036] newfstatat(AT_FDCWD, "/usr/sbin/sleep", 0x7fff55dc25c0, 0) = -1 ENOENT (No such file or directory)
  179. [pid 661036] newfstatat(AT_FDCWD, "/usr/bin/sleep", {st_mode=S_IFREG|0755, st_size=35328, ...}, 0) = 0
  180. [pid 661036] newfstatat(AT_FDCWD, "/usr/bin/sleep", {st_mode=S_IFREG|0755, st_size=35328, ...}, 0) = 0
  181. [pid 661036] geteuid() = 1006
  182. [pid 661036] getegid() = 1002
  183. [pid 661036] getuid() = 1006
  184. [pid 661036] getgid() = 1002
  185. [pid 661036] access("/usr/bin/sleep", X_OK) = 0
  186. [pid 661036] newfstatat(AT_FDCWD, "/usr/bin/sleep", {st_mode=S_IFREG|0755, st_size=35328, ...}, 0) = 0
  187. [pid 661036] geteuid() = 1006
  188. [pid 661036] getegid() = 1002
  189. [pid 661036] getuid() = 1006
  190. [pid 661036] getgid() = 1002
  191. [pid 661036] access("/usr/bin/sleep", R_OK) = 0
  192. [pid 661036] newfstatat(AT_FDCWD, "/usr/bin/sleep", {st_mode=S_IFREG|0755, st_size=35328, ...}, 0) = 0
  193. [pid 661036] newfstatat(AT_FDCWD, "/usr/bin/sleep", {st_mode=S_IFREG|0755, st_size=35328, ...}, 0) = 0
  194. [pid 661036] geteuid() = 1006
  195. [pid 661036] getegid() = 1002
  196. [pid 661036] getuid() = 1006
  197. [pid 661036] getgid() = 1002
  198. [pid 661036] access("/usr/bin/sleep", X_OK) = 0
  199. [pid 661036] newfstatat(AT_FDCWD, "/usr/bin/sleep", {st_mode=S_IFREG|0755, st_size=35328, ...}, 0) = 0
  200. [pid 661036] geteuid() = 1006
  201. [pid 661036] getegid() = 1002
  202. [pid 661036] getuid() = 1006
  203. [pid 661036] getgid() = 1002
  204. [pid 661036] access("/usr/bin/sleep", R_OK) = 0
  205. [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
  206. [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
  207. [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
  208. [pid 661036] execve("/usr/bin/sleep", ["sleep", "20"], 0x55611da10b60 /* 54 vars */) = 0
  209. [pid 661036] brk(NULL) = 0x55fbbd90b000
  210. [pid 661036] arch_prctl(0x3001 /* ARCH_??? */, 0x7fff5bb3c790) = -1 EINVAL (Invalid argument)
  211. [pid 661036] mmap(NULL, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f1c1af61000
  212. [pid 661036] access("/etc/ld.so.preload", R_OK) = -1 ENOENT (No such file or directory)
  213. [pid 661036] openat(AT_FDCWD, "/etc/ld.so.cache", O_RDONLY|O_CLOEXEC) = 3
  214. [pid 661036] newfstatat(3, "", {st_mode=S_IFREG|0644, st_size=95179, ...}, AT_EMPTY_PATH) = 0
  215. [pid 661036] mmap(NULL, 95179, PROT_READ, MAP_PRIVATE, 3, 0) = 0x7f1c1af49000
  216. [pid 661036] close(3) = 0
  217. [pid 661036] openat(AT_FDCWD, "/lib/x86_64-linux-gnu/libc.so.6", O_RDONLY|O_CLOEXEC) = 3
  218. [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
  219. [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
  220. [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
  221. [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
  222. [pid 661036] newfstatat(3, "", {st_mode=S_IFREG|0755, st_size=2220400, ...}, AT_EMPTY_PATH) = 0
  223. [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
  224. [pid 661036] mmap(NULL, 2264656, PROT_READ, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x7f1c1ac00000
  225. [pid 661036] mprotect(0x7f1c1ac28000, 2023424, PROT_NONE) = 0
  226. [pid 661036] mmap(0x7f1c1ac28000, 1658880, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x28000) = 0x7f1c1ac28000
  227. [pid 661036] mmap(0x7f1c1adbd000, 360448, PROT_READ, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x1bd000) = 0x7f1c1adbd000
  228. [pid 661036] mmap(0x7f1c1ae16000, 24576, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x215000) = 0x7f1c1ae16000
  229. [pid 661036] mmap(0x7f1c1ae1c000, 52816, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0x7f1c1ae1c000
  230. [pid 661036] close(3) = 0
  231. [pid 661036] mmap(NULL, 12288, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f1c1af46000
  232. [pid 661036] arch_prctl(ARCH_SET_FS, 0x7f1c1af46740) = 0
  233. [pid 661036] set_tid_address(0x7f1c1af46a10) = 661036
  234. [pid 661036] set_robust_list(0x7f1c1af46a20, 24) = 0
  235. [pid 661036] rseq(0x7f1c1af470e0, 0x20, 0, 0x53053053) = 0
  236. [pid 661036] mprotect(0x7f1c1ae16000, 16384, PROT_READ) = 0
  237. [pid 661036] mprotect(0x55fbbc349000, 4096, PROT_READ) = 0
  238. [pid 661036] mprotect(0x7f1c1af9b000, 8192, PROT_READ) = 0
  239. [pid 661036] prlimit64(0, RLIMIT_STACK, NULL, {rlim_cur=8192*1024, rlim_max=RLIM64_INFINITY}) = 0
  240. [pid 661036] munmap(0x7f1c1af49000, 95179) = 0
  241. [pid 661036] getrandom("\x91\x51\x73\xc6\x31\xd4\xef\x2e", 8, GRND_NONBLOCK) = 8
  242. [pid 661036] brk(NULL) = 0x55fbbd90b000
  243. [pid 661036] brk(0x55fbbd92c000) = 0x55fbbd92c000
  244. [pid 661036] openat(AT_FDCWD, "/usr/lib/locale/locale-archive", O_RDONLY|O_CLOEXEC) = 3
  245. [pid 661036] newfstatat(3, "", {st_mode=S_IFREG|0644, st_size=8872448, ...}, AT_EMPTY_PATH) = 0
  246. [pid 661036] mmap(NULL, 8872448, PROT_READ, MAP_PRIVATE, 3, 0) = 0x7f1c1a200000
  247. [pid 661036] close(3) = 0
  248. [pid 661036] clock_nanosleep(CLOCK_REALTIME, 0, {tv_sec=20, tv_nsec=0}, 0x7fff5bb3c7e0) = 0
  249. [pid 661036] close(1) = 0
  250. [pid 661036] close(2) = 0
  251. [pid 661036] exit_group(0) = ?
  252. [pid 661036] +++ exited with 0 +++
  253. <... wait4 resumed>[{WIFEXITED(s) && WEXITSTATUS(s) == 0}], 0, NULL) = 661036
  254. 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
  255. ioctl(2, TIOCGWINSZ, {ws_row=21, ws_col=200, ws_xpixel=0, ws_ypixel=0}) = 0
  256. ioctl(1, TCGETS, {B38400 opost isig icanon echo ...}) = 0
  257. getuid() = 1006
  258. geteuid() = 1006
  259. getgid() = 1002
  260. getegid() = 1002
  261. getuid() = 1006
  262. geteuid() = 1006
  263. getgid() = 1002
  264. getegid() = 1002
  265. newfstatat(AT_FDCWD, "/home/zhangchen/.terminfo", 0x55611da162f0, 0) = -1 ENOENT (No such file or directory)
  266. newfstatat(AT_FDCWD, "/etc/terminfo", {st_mode=S_IFDIR|0755, st_size=4096, ...}, 0) = 0
  267. newfstatat(AT_FDCWD, "/lib/terminfo", {st_mode=S_IFDIR|0755, st_size=4096, ...}, 0) = 0
  268. newfstatat(AT_FDCWD, "/usr/share/terminfo", {st_mode=S_IFDIR|0755, st_size=4096, ...}, 0) = 0
  269. access("/etc/terminfo/x/xterm-256color", R_OK) = -1 ENOENT (No such file or directory)
  270. access("/lib/terminfo/x/xterm-256color", R_OK) = 0
  271. openat(AT_FDCWD, "/lib/terminfo/x/xterm-256color", O_RDONLY) = 3
  272. newfstatat(3, "", {st_mode=S_IFREG|0644, st_size=3852, ...}, AT_EMPTY_PATH) = 0
  273. read(3, "\36\2%\0&\0\17\0\235\1Z\6xterm-256color|xterm"..., 32768) = 3852
  274. read(3, "", 28672) = 0
  275. close(3) = 0
  276. ioctl(1, TCGETS, {B38400 opost isig icanon echo ...}) = 0
  277. ioctl(1, TCGETS, {B38400 opost isig icanon echo ...}) = 0
  278. ioctl(1, TCGETS, {B38400 opost isig icanon echo ...}) = 0
  279. ioctl(1, TCGETS, {B38400 opost isig icanon echo ...}) = 0
  280. ioctl(1, TIOCGWINSZ, {ws_row=21, ws_col=200, ws_xpixel=0, ws_ypixel=0}) = 0
  281. ioctl(0, TIOCGWINSZ, {ws_row=21, ws_col=200, ws_xpixel=0, ws_ypixel=0}) = 0
  282. brk(0x55611da41000) = 0x55611da41000
  283. rt_sigprocmask(SIG_SETMASK, [], NULL, 8) = 0
  284. --- SIGCHLD {si_signo=SIGCHLD, si_code=CLD_EXITED, si_pid=661036, si_uid=1006, si_status=0, si_utime=0, si_stime=0} ---
  285. wait4(-1, 0x7fff55dc2210, WNOHANG, NULL) = -1 ECHILD (No child processes)
  286. rt_sigreturn({mask=[]}) = 0
  287. read(255, "", 11) = 0
  288. rt_sigprocmask(SIG_BLOCK, [CHLD], [], 8) = 0
  289. rt_sigprocmask(SIG_SETMASK, [], NULL, 8) = 0
  290. exit_group(0) = ?
  291. +++ 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子进程,如下所示。

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

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

  1. # 文件test.sh
  2. #############################
  3. a=1
  4. (echo $a)
  5. #############################
  6. $ bash test.sh
  7. 输出:1

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

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

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

  1. # 文件test.sh
  2. #############################
  3. echo $BASHPID
  4. (echo $BASHPID)
  5. #############################
  6. $ bash test.sh
  7. 输出:
  8. 681607
  9. 681608

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

  1. # 文件test.sh
  2. #############################
  3. echo $BASH_SUBSHELL
  4. (echo $BASH_SUBSHELL;(echo $BASH_SUBSHELL))
  5. #############################
  6. $ bash test.sh
  7. 输出:
  8. 0
  9. 1
  10. 2

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

  1. $ su -l *****
  2. Password:
  3. $ echo $SHLVL
  4. 1
  5. $ bash
  6. $ echo $SHLVL
  7. 2
  8. # 文件test.sh
  9. #############################
  10. echo $SHLVL
  11. (echo $SHLVL)
  12. #############################
  13. $ bash test.sh
  14. 输出:
  15. 2
  16. 2
本文内容由网友自发贡献,转载请注明出处:https://www.wpsshop.cn/w/秋刀鱼在做梦/article/detail/778397
推荐阅读
相关标签
  

闽ICP备14008679号