Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/bash/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/shell/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Bash 如何制作一个简单的shell脚本来检查系统是否有一个具有指定名称的进程?_Bash_Shell_Operating System - Fatal编程技术网

Bash 如何制作一个简单的shell脚本来检查系统是否有一个具有指定名称的进程?

Bash 如何制作一个简单的shell脚本来检查系统是否有一个具有指定名称的进程?,bash,shell,operating-system,Bash,Shell,Operating System,这几乎是一个脚本,用于检查系统是否具有指定名称的进程。如果它确实找到了任何一个进程,它会杀死所有进程,并报告有多少进程被终止,否则它会回显不存在这样的进程 例如: $terminateProcess[正在运行的cpp程序] 应该杀死所有[给定文件名]进程 任何人都能让我开始吗?无需编写shell脚本,pkill已经存在多年了。曼吉尔: pkill will send the specified signal (by default SIGTERM) to each p

这几乎是一个脚本,用于检查系统是否具有指定名称的进程。如果它确实找到了任何一个进程,它会杀死所有进程,并报告有多少进程被终止,否则它会回显不存在这样的进程

例如: $terminateProcess[正在运行的cpp程序] 应该杀死所有[给定文件名]进程


任何人都能让我开始吗?

无需编写shell脚本,pkill已经存在多年了。曼吉尔:

 pkill  will  send  the  specified  signal  (by default SIGTERM) to each
       process instead of listing them on stdout.

       -c, --count
              Suppress  normal  output; instead print a count of matching pro‐
              cesses.  When count does not match anything, e.g. returns  zero,
              the command will return non-zero value.

       Example 2: Make syslog reread its configuration file:
              $ pkill -HUP syslogd

在开始编写自己的程序之前,您应该检查这样的程序是否已经存在。然后,您将找到
pkill
,从而节省一些精力。