execShell.c
来源:互联网 发布:mac怎么解压缩zip 编辑:程序博客网 时间:2024/04/29 11:13
#include <stdio.h>
#include <stdlib.h>
#define BUFSIZE 100
int main()
{
int ret1 = 0;
int ret2 = 0;
char buf[BUFSIZE];
FILE *fp = NULL;
char ch ;
int flag1 = 0;
int flag2 = 0;
char pidBuf[10];
int index = 0;
int result = 0;
printf("当前进程的进程号为%d/n",getpid());
ret1 = system("ps aux > ps.txt");
printf("ret1 = %d/n",ret1);
if(0 != ret1)
{
printf("system is called failed/n");
return ;
}
ret2 = system("grep bash ps.txt> grep.txt");
printf("ret2 = %d/n",ret2);
if(127 == ret2 | ret2 < 0)
{
printf("system is called failed/n");
return ;
}
fp = fopen("grep.txt","r+");
if(NULL == fp)
{
printf("can not open file grep.txt/n");
return ;
}
while(EOF != (ch = getc(fp)))
{
if (' ' == ch && 0 == flag1)
{
flag1 = 1;
}
if (1 == flag1 && ' ' != ch)
{
pidBuf[index++] = ch;
flag2 = 1;
}
if (1 == flag2 && ' ' == ch)
{
pidBuf[index] = '/0';
break;
}
}
result = atoi(pidBuf);
printf("%s,%d/n",pidBuf,result);
return 0;
}
- execShell.c
- Exec vs ExecWait vs ExecShell vs nsExec::Exec vs nsExec::ExecToLog vs nsExec::ExecToStack vs ExecDos
- c
- c
- c
- c
- C
- c
- c
- c
- C+
- c
- C
- c
- c
- c
- C
- C
- .net设置字体
- 翻译小窍门-女人吃啥让胸部更丰满
- 翻译小窍门-如果你有放不下的人
- 重新学习带宽的概念
- 翻译小窍门-谢谢你勾引我老公
- execShell.c
- 三种开源跨平台GUI toolkits—— GTK、Qt和wxWidgets
- 翻译小窍门-教你变美的100种潮流发型
- colorChage.c
- vc6.0使用问题积累
- sender.c ,receiver.c
- 串口编程C++实例(CE)
- 到google面试 google的21道面试问题
- POJ 3507