小编End*_*der的帖子

检查进程是否存在

我想编写接受进程名称的脚本(我每次都询问用户进程名称,然后在同一行上提示)如果进程存在,它将打印“存在”,如果不存在,则打印“不存在”,具体取决于系统上当前是否存在这样的进程。

例子:

Enter the name of process: bash
exists
Enter the name of process: bluesky
does not exist
Run Code Online (Sandbox Code Playgroud)

我的代码:

#!/bin/bash
while true
do
read -p "Enter the name of process: "
 if [ pidof -x > 0 ]; then
    echo "exists"   
 else    
    echo "does not exist"
 fi 
done 
Run Code Online (Sandbox Code Playgroud)

我收到的错误消息。

pidof: unary operator expected
Run Code Online (Sandbox Code Playgroud)

bash process

2
推荐指数
2
解决办法
2422
查看次数

标签 统计

bash ×1

process ×1