进程方式
int check_process(char *pName)
{
FILE *fp;
int result_buf;
char temp_cmd[256];
int ret=0;
sprintf(temp_cmd, "ps -ef | grep \"%s\" | grep -v \"grep\" | wc -l", pName);
fp = popen(temp_cmd, "r");
if (NULL == fp)
{
ret = 0;
printf("system errr!!!\n");
}
else
{
if( (result_buf = fgetc(fp)) != EOF)
{
if(result_buf >= '1')
{
ret =1;
}
else
{
ret = -1;
}
}
else
{
ret = 0;
}
}
pclose(fp);
return ret;
}
shell脚本
#########################################################################
# File Name: start.sh
# Author: luoyk
# Created Time: 2021年09月28日 星期二 19时01分06秒
#########################################################################
#!/bin/bash
while true
do
count=`ps -ef | grep 进程名 | grep -v "grep" | wc -l` >/dev/null
if [[ $count == 0 ]];then
运行进程
fi
sleep 3
#done