[英]Execute a block in the same shell
Im' trying to find a way to execute a block in the same way I would execute a code calling an external script. 我试图找到一种方法来执行块,就像执行调用外部脚本的代码一样。
Let me exemplify ... 让我举例说明...
# caller.sh
!#/bin/bash
/soft/executer.sh &
After executing "caller.sh", the "ps" command return will be something like: 执行“ caller.sh”后,“ ps”命令返回将类似于:
PID TTY TIME CMD
19566 pts/7 00:00:00 bash
22689 pts/7 00:00:00 executer.sh
22694 pts/7 00:00:00 ps
But if a change the way to call the script "caller.sh" like this: 但是,如果像这样改变了调用脚本“ caller.sh”的方式,则:
# caller.sh
!#/bin/bash
{
/soft/executer.sh
} &
The "ps" command shows up both commands (caller.sh and executer.sh) “ ps”命令同时显示两个命令(caller.sh和executer.sh)
PID TTY TIME CMD
19566 pts/7 00:00:00 bash
22689 pts/7 00:00:00 caller.sh
22694 pts/7 00:00:00 ps
22685 pts/7 00:00:00 executer.sh
Both "caller.sh" and "ler.sh" commands are showing up. 同时显示“ caller.sh”和“ ler.sh”命令。
I know I could simply use the first option to call this, but this is just a simple example to ask how to unlik the processes "caller.sh" and "execute.sh" in the second example that uses blocks 我知道我可以简单地使用第一个选项来调用它,但这只是一个简单的示例,询问在使用块的第二个示例中如何取消处理“ caller.sh”和“ execute.sh”进程
Thanks 谢谢
I would try this in caller.sh: 我会在caller.sh中尝试:
#!/bin/bash
(
exec /soft/executer.sh
)&
The issue is that a block or subshell is merely a copy of the parent meaning the parent may be gone, but the child has the same name therefore shows up in ps. 问题在于,块或子外壳仅仅是父级的副本,意味着父级可能已消失,但是子级具有相同的名称,因此以ps显示。 So, if you have: 因此,如果您有:
#!/bin/bash
(
/soft/executer.sh
)&
sleep 60
You will see two copies of caller.sh (the parent and the child). 您将看到caller.sh的两个副本(父级和子级)。 The parent is sleeping and the child is waiting for executer.sh to finish. 父级正在睡觉,子级正在等待executer.sh完成。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.