프로세스 갯수 알아내기..


config파일과 프로세스와의 연계?? 가 필요해서 
혼자서 잡질..
joinc가니가 소스가 있긴하던데..(ps 만들기...)
걍안보고 해봤음.................
덧> 꺽쇠는 문자 망할놈의 태그땜에..

#include<stdio.h>
#include<stdlib.h>
#include<unistd.h>
#include<sys/types.h>
#include<dirent.h>
#include<sys/stat.h>
#include<fcntl.h>
#include<string.h>
 
#define FALSE 0
#define TRUE !FALSE
#define PROCESS_NAME "myterm"           //찾아낼 프로세스 이름
 
int CharDigit(char *data)               //chk할 문자열을 받는다 다숫자가 마즈면 TRUE else FALSE
{
    while(*data!='\0'){
        if(!isdigit((int)*data)){
            return FALSE;
        }
            data++;
    }
    return TRUE;
}

int main(void)
{
     DIR *op_proc;
     struct dirent *rd_proc;
     int fd;
     char path[50];
     char buf[50];
     char *po;
     int ps_num=0;
 
     if((op_proc=opendir("/proc"))==NULL){      
         perror("디렉토리 열기가 실패했습니다!");
         exit(2);
     }
 
     while((rd_proc=readdir(op_proc))!=NULL){     
 
         if(CharDigit(rd_proc->d_name))  {        //숫자라면
             memset(path,0,sizeof(path));
             sprintf(path,"/proc/%s/status",rd_proc->d_name);
 
             if((fd=open(path,O_RDONLY))==-1){
                 perror("파일 열기 가 실패했습니다!");
                 continue;
             }
 
             read(fd,buf,sizeof(buf));
 
             //파싱..
             strtok(buf,"\n");
             po=strchr(buf,(int)'\t');
             po++;
 
             if(strcmp(po,PROCESS_NAME)==0)
                 ps_num++;
         }
 
     }
 
     printf("프로세스 갯수:%d\n",ps_num);
     return 0;
}
쫌 고쳤는데 컴파일 잘될려나...