C語言實現(xiàn)查看進程是否存在的方法示例
更新時間:2017年07月27日 11:10:48 作者:lifan5
這篇文章主要介紹了C語言實現(xiàn)查看進程是否存在的方法,涉及C語言針對進程操作的相關實現(xiàn)技巧,需要的朋友可以參考下
本文實例講述了C語言實現(xiàn)查看進程是否存在的方法。分享給大家供大家參考,具體如下:
#include<unistd.h>
#include<sys/types.h>
#include<sys/wait.h>
#include<stdio.h>
#include<stdlib.h>
#include<fcntl.h>
#include<limits.h>
#define BUFSZ 150
void err_quit(char *msg)
{
perror(msg);
exit(EXIT_FAILURE);
}
int main(int argc, char *argv[])
{
FILE* fp;
int count;
char buf[BUFSZ];
char command[150];
sprintf(command, "ps -ef | grep **** | grep -v grep | wc -l" );
if((fp = popen(command,"r")) == NULL)
err_quit("popen");
if( (fgets(buf,BUFSZ,fp))!= NULL )
{
count = atoi(buf);
if(count == 0)
printf("not found\n");
else
printf("process :tdv1 total is %d\n",count);
}
pclose(fp);
exit(EXIT_SUCCESS);
}
希望本文所述對大家C語言程序設計有所幫助。
相關文章
C語言數(shù)據(jù)結構算法基礎之循環(huán)隊列示例
這篇文章主要為大家介紹了C語言數(shù)據(jù)結構算法基礎之循環(huán)隊列,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪2022-06-06

