📄 lookall.c
字号:
/******************************************************
程序功能: 清理主控程序异常终止后产生的残余进程
田科钰 2006年9月9日 于
*******************************************************/
#include <stdio.h>
#include <string.h>
#include <math.h>
//#include <stdlib.h>
char LDZProc[][64] = { "a","b","dual_host"};
char ServerProc[][64] = { "./a","dual_host"};
//
char ServerProcOK[64]; //对应的进程是否存在,存在:1,不存在:0
int psflag=1; //1,ServerPproc;2,oracle;3,LDZPproc
int killflag=1; //kill -9
int main()
{
FILE *fd;
char aBuf[512];
int pid,nProc;
char name[512];
int i,nServerProc;;
//system("ps -o pid -o comm -A > ccc.dat");
system("ps -ef -x > ccc.dat");
if((fd=fopen("ccc.dat","r"))==NULL)
{
printf("cant open file 无法打开文件:ccc.dat\n");
return -1;
}
memset(ServerProcOK,0,64);
nServerProc = sizeof(ServerProc)/64;
//printf("BBBBBBBB_nServerProc=%d\n",nServerProc);
fgets(aBuf,512,fd);
//printf("\n==========清理残余应用进程============\n");
printf("\n==========查看应用软件进程============\n");
printf("==========系统应有./a,dual_host,dual_host,sys_in,sys_out,sys_proc,db_out,mnt \n\t statis,net2_in,net2_out,distr,binsysin,qbffcl,qbffout,distrbin 共16个进程!=======\n");
//printf("\n==========查看oracle数据库进程============\n");
//printf("==========系统共有17个 ora_ 进程,1个tnslsnr监听进程,多个oracleinfo客户端连接进程!=======\n");
printf(" UID PID PPID CPU STIME TTY TIME COMMAND\n");
nProc=0;
while(!feof(fd))
{
//aBuf[0]=0;
//pid=0;
//name[0]=0;
if (fgets(aBuf,512,fd) == NULL)
{
printf("\t -----------------------------------\n");
break;//已到文件尾,aBuf未赋值
}
sscanf(aBuf,"%*s %d %[^!]",&pid,name);
//printf("\t %d %s",pid,name);
//if (bIsLDZProcess(name))
if (bIsServerProcess(aBuf,nServerProc))
{
char cmd[128];
nProc = nProc+1;
printf("\t %d %s",pid,name);
sprintf(cmd,"kill -9 %d",pid);
//printf("cmd=%s\n",cmd);
//system(cmd);
}
}
fclose(fd);
//printf("\n\n==========共有%d个残余进程被清除成功!=======\n",nProc);
printf("\n==========系统现有%d个应用进程!,缺少以下进程=======\n",nProc);
//printf("\n\n==========系统现有%d个oracle进程!=======\n",nProc);
for (i=0;i<nServerProc;i++)
{
if(ServerProcOK[i] == 0) //对应的进程是否存在,存在:1,不存在:0
{
printf("\t xxxx %s\n",ServerProc[i]);
}
}
return 0;
}
int bIsLDZProcess(char *name)
{
int nLDZProc;
nLDZProc = sizeof(LDZProc)/64;
for (int i=0;i<nLDZProc;i++)
{
if (strncmp(LDZProc[i],name,8)==0)
{
//printf("name=%s\n",name);
return 1;
}
}
//printf("\n");
//printf("nLDZProc=%d\n",nLDZProc);
return 0;
}
int bIsServerProcess(char *name,int nServerProc)
{
char *pStr;
//nServerProc = sizeof(ServerProc)/64;
for (int i=0;i<nServerProc;i++)
{
if ((pStr=strrstr(name,ServerProc[i]))!=NULL)
{
if (strchr(pStr,'/')!=NULL && pStr[0]!='.')
continue; //非进程名
//printf("%s",name);
ServerProcOK[i] = 1; //对应的进程是否存在,存在:1,不存在:0
//printf("AAAAAAAA_i=%d,name=%s\n",i,name);
return 1;
}
}
//printf("\n");
//printf("nServerProc=%d\n",nServerProc);
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -