简体   繁体   English

bash-为什么(cd && sleep 5000)开始第二个进程

[英]bash - why does ( cd && sleep 5000 ) start second process

I have this script test.sh 我有这个脚本test.sh

#!/bin/bash
( cd . && sleep 5000 )

I execute with ./test.sh & and then run ps lax | grep test.sh 我用./test.sh &执行,然后运行ps lax | grep test.sh ps lax | grep test.sh

I now have 2 processes running... 我现在有2个进程正在运行...

0  1000  6883  6600  20   0  10600  1332 -      S    pts/2      0:00 /bin/bash ./test.sh
1  1000  6884  6883  20   0  10604   704 -      S    pts/2      0:00 /bin/bash ./test.sh
  • Why do I have two processes running and where does the second process come from? 为什么我有两个运行的进程,第二个进程从何而来?
  • Why don't I have two processes if I remove the cd ".." from the command? 如果从命令中删除cd ".." ,为什么没有两个进程?

Thanks for any explanation, I just don't get it and I think I'm lacking some basics here... or is this some vodoo? 感谢您的解释,我只是听不懂,我想这里缺少一些基础知识...还是这是一些巫毒教? ;) ;)

在括号内对一系列bash命令进行分组将在子shell中执行它们。

Writing two commands together might pose some difficulties for Terminal to detect the commands. 一起编写两个命令可能会给终端检测命令带来一些困难。 Perhaps you could split it up into 2 commands. 也许您可以将其分为2个命令。

cd ...

sleep 5000

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM