C語言實現(xiàn)查看進程是否存在的方法示例
更新時間:2017年07月27日 11:10:48 作者:lifan5
這篇文章主要介紹了C語言實現(xiàn)查看進程是否存在的方法,涉及C語言針對進程操作的相關(guān)實現(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語言程序設(shè)計有所幫助。
相關(guān)文章
Qt中關(guān)聯(lián)容器QMap,QMultiMap,QHash,QMultiHash的使用
本文主要介紹了Qt中關(guān)聯(lián)容器QMap,QMultiMap,QHash,QMultiHash的使用,這些關(guān)聯(lián)容器在Qt中提供了靈活而強大的數(shù)據(jù)結(jié)構(gòu)選項,根據(jù)具體的需求和使用場景,您可以選擇適合的容器來存儲和管理數(shù)據(jù),感興趣的可以了解一下2023-09-09
解析VC中創(chuàng)建DLL,導(dǎo)出全局變量,函數(shù)和類的深入分析
本篇文章是對VC中創(chuàng)建DLL,導(dǎo)出全局變量,函數(shù)和類進行了詳細的分析介紹,需要的朋友參考下2013-05-05

