#include<stdio.h>
char ps[1000][1000];
int ps_id[1000];
char ps_name[1000][1000];
char kill[100];
int main()
{
FILE *fp;
FILE *fp1;
int id;
fp1=fopen("psid.txt","r");
int count=0,i,dis=0;
char temp[100];
system("ps -e > test.txt");
fp=fopen("test.txt","r");
fscanf(fp1,"%d",&id);
while(fgets(ps[count],1000,fp)){
count++;
}
for(i=0;i<count;i++)
sscanf(ps[i],"%d %*s %*s %s",&ps_id[i],ps_name[i]);
for(i=0;i<count;i++){
if(strcmp(ps_name[i],"a.out")==0){ //a.out만 원하는 프로그램명으로 바꾸면 됨.
if(dis==0)
dis=1;
else{
sprintf(kill,"kill -9 %d",ps_id[i]);
printf("%s\n",kill);
system(kill);
}
}
}
return 0;
}
ps -e >> test.txt 명령어로 모든프로세스를 test.txt파일에 저장하고 파일을 읽어들인다.
멀티프로세스 서버 소켓을 사용하던 도중 자식프로세스가 죽지 않고 남아있어서 심심해서 작성해봤는데... 실질적인 문제는 이게 아니고 자식프로세스가 좀비로 변해버려서 죽지않아요 ㅠㅠ
이 좀비들....ㅋ.....
'System > Linux' 카테고리의 다른 글
리눅스 core file (0) | 2013.03.18 |
---|---|
nohup (0) | 2013.03.18 |
리눅스 tee 명령어 (0) | 2013.03.14 |
Mac Address 바꾸기 (0) | 2012.06.28 |
Linux 디렉토리 구조 (0) | 2012.06.07 |