64,281
社区成员
发帖
与我相关
我的任务
分享
#!/bin/sh
while [1]
do
//取进程数目,具体查一下ps命令
//grep -w 'drmagent' 严格配置名字是'drmagent'的进程
//grep -v grep 去掉本条语句 "ps -ef ¦ grep -w 'drmagent' ¦ grep -v grep ¦ wc -l "
//wc -l 统计行数
PROCESSNUM = ps -ef ¦ grep -w 'drmagent' ¦ grep -v grep ¦ wc -l
echo $PROCESSNUM
if [ $PROCESSNUM -lt 1 ]; then // -lt 小于
./启动脚本
fi
done
int detect_process(char * process_name)
{
FILE *ptr;
char buff[512];
char ps[128];
sprintf(ps,"ps -e | grep -c ' %s$'",process_name);
strcpy(buff,"ABNORMAL");
if((ptr=popen(ps, "r")) != NULL)
{
while (fgets(buff, 512, ptr) != NULL)
{
if(atoi(buff)>=2)
{
pclose(ptr);
return CONFLICT;
}
}
}
if(strcmp(buff,"ABNORMAL")==0) /*ps command error*/
return ERROR;
pclose(ptr);
return NOERROR;
}