no message
parent
c0e60bfd55
commit
8e06ef30a1
|
@ -1,7 +1,7 @@
|
|||
/*
|
||||
* @Author: your name
|
||||
* @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
|
||||
* @Description: In User Settings Edit
|
||||
* @FilePath: \generallib\general\src\function\daemon.c
|
||||
|
@ -300,10 +300,67 @@ int DaemonizeMonitor::StopMonitor(string){
|
|||
#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){
|
||||
if(path ==""){
|
||||
return -1;
|
||||
}
|
||||
if(!file_existed(path)){
|
||||
return -1;
|
||||
}
|
||||
#ifdef _WIN32
|
||||
if(m_running_pid.find(path) != m_running_pid.end()){
|
||||
DWORD pid = m_running_pid.at(path);
|
||||
|
@ -316,4 +373,8 @@ int DaemonizeMonitor::StopProcess(string path){
|
|||
}
|
||||
return 0;
|
||||
#endif
|
||||
#ifdef linux
|
||||
std::thread p(_process_start,path);
|
||||
p.detach();
|
||||
#endif
|
||||
}
|
|
@ -1,7 +1,7 @@
|
|||
/*
|
||||
* @Author: your name
|
||||
* @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
|
||||
* @Description: In User Settings Edi
|
||||
* @FilePath: \generallib\general\src\function\daemon.h
|
||||
|
@ -25,7 +25,9 @@ extern "C"{
|
|||
#include <vector>
|
||||
#include <map>
|
||||
#include <stdint.h>
|
||||
#include <thread>
|
||||
class DaemonizeMonitor{
|
||||
|
||||
public:
|
||||
DaemonizeMonitor(string path);
|
||||
int AddNewProcess(string);
|
||||
|
|
Loading…
Reference in New Issue