通过运行程序名判断程序是否处于运行状态
输入进程的名称,如果此程序在运行则返回此程序的运行ID,否则返回-1
static int detect_process(const char * process_name) //判断进程是否在运行
{
int n = -1;
FILE *strm;
char buf[128]={0};
sprintf(buf,"ps -ef | grep %s|grep -v grep", process_name);
if((strm=popen(buf, "r")) != NULL)
{
if(fgets(buf, sizeof(buf), strm) != NULL)
{
n = atoi(buf);
}
}else
{
return -1;
}
pclose(strm);
return n;
}