Linux 使用名称启动进程

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11130229/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-06 06:59:09  来源:igfitidea点击:

Start a process with a name

linuxprocesskill-process

提问by cache

Basically I want to dynamically start some processes which may create their own children processes, also I want to kill a certain group of processes I just created whenever I want. One way I could think of is to start processes with a name(to distinguish as a group), then use pkill to kill them by the name. The question is how to start a process with a name so that I can use pkill to kill them by the name? I am open to other solutions as well.

基本上我想动态启动一些可能会创建自己的子进程的进程,我也想随时杀死我刚刚创建的某个进程组。我能想到的一种方法是使用名称启动进程(以区分为一个组),然后使用 pkill 按名称杀死它们。问题是如何使用名称启动进程,以便我可以使用 pkill 按名称杀死它们?我也愿意接受其他解决方案。

采纳答案by schadr

There is very similar question on serverfaultwith some answers that might help you

serverfault 上有一个非常相似的问题,其中的一些答案可能对您有所帮助

回答by user2829759

How can I start a process with a different name?

如何启动具有不同名称的进程?

bash -c "exec -a <MyProcessName> <Command>"

Then you can kill the process with:

pkill -f MyProcessName

bash -c "exec -a <MyProcessName> <Command>"

然后您可以使用以下命令终止该进程:

pkill -f MyProcessName