no message

master
zcy 2021-08-01 19:50:22 +08:00
parent c0e60bfd55
commit 8e06ef30a1
2 changed files with 65 additions and 2 deletions

View File

@ -1,7 +1,7 @@
/* /*
* @Author: your name * @Author: your name
* @Date: 2021-07-23 23:39:57 * @Date: 2021-07-23 23:39:57
* @LastEditTime: 2021-07-29 00:14:47 * @LastEditTime: 2021-08-01 15:47:32
* @LastEditors: Please set LastEditors * @LastEditors: Please set LastEditors
* @Description: In User Settings Edit * @Description: In User Settings Edit
* @FilePath: \generallib\general\src\function\daemon.c * @FilePath: \generallib\general\src\function\daemon.c
@ -300,10 +300,67 @@ int DaemonizeMonitor::StopMonitor(string){
#endif #endif
} }
inline bool file_existed (const std::string& name) {
if (FILE *file = fopen(name.c_str(), "r")) {
fclose(file);
return true;
} else {
return false;
}
}
#ifdef linux
void _process_start(string path){
auto file = popen(path.c_str(),"r");
if(file < 0){
fprintf(stderr,"execl failed:%s",strerror(errno));
return;
}
pclose(file);
}
int prep_map(){
FILE *pstr;
char cmd[128],buff[512],*p;
int iPID;
int pidPosition=1;
int pInfoPosition=7;
memset(cmd,0,sizeof(cmd));
sprintf(cmd, "ps ");
pstr = popen(cmd, "r");
if(pstr==NULL) {
return 1;
}
memset(buff,0,sizeof(buff));
while( 1 ) {
fgets(buff,512,pstr);
if(feof(pstr))
{
break;
}
printf("buffer=%s",buff);
}
pclose(pstr);
return 1;
}
#endif
/* /*
*/ */
int DaemonizeMonitor::StopProcess(string path){ int DaemonizeMonitor::StopProcess(string path){
if(path ==""){
return -1;
}
if(!file_existed(path)){
return -1;
}
#ifdef _WIN32 #ifdef _WIN32
if(m_running_pid.find(path) != m_running_pid.end()){ if(m_running_pid.find(path) != m_running_pid.end()){
DWORD pid = m_running_pid.at(path); DWORD pid = m_running_pid.at(path);
@ -316,4 +373,8 @@ int DaemonizeMonitor::StopProcess(string path){
} }
return 0; return 0;
#endif #endif
#ifdef linux
std::thread p(_process_start,path);
p.detach();
#endif
} }

View File

@ -1,7 +1,7 @@
/* /*
* @Author: your name * @Author: your name
* @Date: 2021-07-23 23:40:36 * @Date: 2021-07-23 23:40:36
* @LastEditTime: 2021-07-26 00:03:14 * @LastEditTime: 2021-08-01 13:17:35
* @LastEditors: Please set LastEditors * @LastEditors: Please set LastEditors
* @Description: In User Settings Edi * @Description: In User Settings Edi
* @FilePath: \generallib\general\src\function\daemon.h * @FilePath: \generallib\general\src\function\daemon.h
@ -25,7 +25,9 @@ extern "C"{
#include <vector> #include <vector>
#include <map> #include <map>
#include <stdint.h> #include <stdint.h>
#include <thread>
class DaemonizeMonitor{ class DaemonizeMonitor{
public: public:
DaemonizeMonitor(string path); DaemonizeMonitor(string path);
int AddNewProcess(string); int AddNewProcess(string);