diff --git a/general/src/function/daemon.cpp b/general/src/function/daemon.cpp index 7d14b5b..305a2c8 100644 --- a/general/src/function/daemon.cpp +++ b/general/src/function/daemon.cpp @@ -1,7 +1,7 @@ /* * @Author: your name * @Date: 2021-07-23 23:39:57 - * @LastEditTime: 2021-08-11 01:15:55 + * @LastEditTime: 2021-08-12 00:34:35 * @LastEditors: Please set LastEditors * @Description: In User Settings Edit * @FilePath: \generallib\general\src\function\daemon.c @@ -17,7 +17,6 @@ void _process_start(string path){ } pclose(file); } - vector StripList(const char *in,const char* d){ vector ret; vector pos; @@ -30,11 +29,6 @@ vector StripList(const char *in,const char* d){ int len = strlen(in); int sublen = strlen(d); - for(int i = 0;i < strlen(in);i++){ - std::cout< StripList(const char *in,const char* d){ } } if(found){ - // printf("pos start %d\r\n",i); i += sublen - 1; pos.push_back(i); continue; @@ -64,7 +57,6 @@ vector StripList(const char *in,const char* d){ pos_strip_continue.push_back(pos_strip_continue[pos_strip_continue.size() - 1] + 2); pos_strip_continue.push_back(strlen(in) - 1); } - std::cout< StripList(const char *in,const char* d){ return ret; } -int prep_map(){ - FILE *pstr; +typedef struct{ + uint16_t pid; + string process_name; +}RuningProcess; + + +vector RangeProcess(){ + FILE *pstr; char cmd[128],buff[512],*p; + vector ret; int iPID; - const char *name= "mongod";//要查找的进程�? - - int pidPosition=1; - int pInfoPosition=7; - + int pidPosition = 1; + int pInfoPosition = 7; + memset(cmd,0,sizeof(cmd)); - sprintf(cmd, "ps "); pstr = popen(cmd, "r"); - + if(pstr==NULL) { - return 1; + return ret; } memset(buff,0,sizeof(buff)); + bool first = true; while( 1 ) { + RuningProcess ins; fgets(buff,512,pstr); + if(first){ + first = false; + continue; + } if(feof(pstr)) { break; } - printf("buffer=%s",buff); - + auto trip = StripList(buff," "); + ins.pid = atoi(trip[0].c_str()); + ins.process_name = trip[3]; + ret.push_back(ins); } pclose(pstr); - return 1; + return ret; } + #endif