From 8e06ef30a18d991a4d5eedfd58f6e6db5aa605f4 Mon Sep 17 00:00:00 2001 From: zcy <290198252@qq.com> Date: Sun, 1 Aug 2021 19:50:22 +0800 Subject: [PATCH] no message --- general/src/function/daemon.cpp | 63 ++++++++++++++++++++++++++++++++- general/src/function/daemon.h | 4 ++- 2 files changed, 65 insertions(+), 2 deletions(-) diff --git a/general/src/function/daemon.cpp b/general/src/function/daemon.cpp index 37e0aef..cf273b9 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-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 } \ No newline at end of file diff --git a/general/src/function/daemon.h b/general/src/function/daemon.h index 640c23d..6aba2b1 100644 --- a/general/src/function/daemon.h +++ b/general/src/function/daemon.h @@ -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 #include #include +#include class DaemonizeMonitor{ + public: DaemonizeMonitor(string path); int AddNewProcess(string);