no message
parent
c1a585546e
commit
170597e656
|
@ -1,7 +1,7 @@
|
|||
/*
|
||||
* @Author: your name
|
||||
* @Date: 2021-07-23 23:39:57
|
||||
* @LastEditTime: 2021-08-01 15:47:32
|
||||
* @LastEditTime: 2021-08-06 01:07:45
|
||||
* @LastEditors: Please set LastEditors
|
||||
* @Description: In User Settings Edit
|
||||
* @FilePath: \generallib\general\src\function\daemon.c
|
||||
|
@ -17,28 +17,51 @@ void _process_start(string path){
|
|||
}
|
||||
pclose(file);
|
||||
}
|
||||
|
||||
vector<string> StripList(const char *in,const char* d){
|
||||
vector<string> ret;
|
||||
vector<uint16_t> pos;
|
||||
vector<uint16_t> pos_strip_continue;
|
||||
|
||||
int lastpos = -1;
|
||||
if((nullptr == in)|| (nullptr == d)){
|
||||
return ret;
|
||||
}
|
||||
int len = strlen(in);
|
||||
int sublen = strlen(d);
|
||||
|
||||
for(int i = 0;i < strlen(in);i++){
|
||||
std::cout<<i<<"#"<<in[i];
|
||||
}
|
||||
std::cout<<std::endl;
|
||||
|
||||
if( len <= 0)
|
||||
return ret;
|
||||
if(sublen <= 0)
|
||||
return ret;
|
||||
|
||||
for(int i = 0;i < (len - strlen(d)) ; i++){
|
||||
std::cout<<i<<std::endl;
|
||||
bool found = true;
|
||||
for(int j = 0;j < strlen(d);j++){
|
||||
if(in[i + j] == d[j]){
|
||||
if(in[i + j] != d[j]){
|
||||
found = false;
|
||||
}
|
||||
}
|
||||
if(found){
|
||||
string x();
|
||||
i+= strlen(d);
|
||||
printf("pos start %d\r\n",i);
|
||||
i += sublen - 1;
|
||||
pos.push_back(i);
|
||||
continue;
|
||||
}
|
||||
printf("%d\r\n",i);
|
||||
|
||||
}
|
||||
for(int i = 0; i < pos.size() - 1;i++){
|
||||
if(pos[i + 1] != (pos[i] + sublen)){
|
||||
pos_strip_continue.push_back(pos[i]);
|
||||
pos_strip_continue.push_back(pos[i + 1]);
|
||||
}
|
||||
}
|
||||
pos_strip_continue.push_back(strlen(in) - 1);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
@ -46,7 +69,7 @@ int prep_map(){
|
|||
FILE *pstr;
|
||||
char cmd[128],buff[512],*p;
|
||||
int iPID;
|
||||
const char *name= "mongod";//è¦<EFBFBD>查找的进程å<EFBFBD>?
|
||||
const char *name= "mongod";//要查找的进程<EFBFBD>?
|
||||
|
||||
int pidPosition=1;
|
||||
int pInfoPosition=7;
|
||||
|
@ -193,12 +216,12 @@ static int test_fork()
|
|||
STARTUPINFO si = {sizeof(si)};
|
||||
PROCESS_INFORMATION pi;
|
||||
si.dwFlags = STARTF_USESHOWWINDOW; //指定wShowWindow成员有效
|
||||
si.wShowWindow = TRUE; //æ¤æˆ<EFBFBD>员设为TRUEçš„è¯<EFBFBD>则显示新建进程的主窗å<EFBFBD>?
|
||||
si.wShowWindow = TRUE; //此成员设为TRUE的话则显示新建进程的主窗<EFBFBD>?
|
||||
BOOL bRet = CreateProcess(
|
||||
NULL, //不在此指定可执行文件的文件名
|
||||
szCommandLine, //命令行å<EFBFBD>‚æ•?
|
||||
NULL, //默认进程安全�
|
||||
NULL, //默认进程安全�
|
||||
szCommandLine, //命令行参<EFBFBD>?
|
||||
NULL, //默认进程安全<EFBFBD>?
|
||||
NULL, //默认进程安全<EFBFBD>?
|
||||
FALSE, //指定当前进程内句柄不可以被子进程继承
|
||||
CREATE_NEW_CONSOLE, //为新进程创建一个新的控制台窗口
|
||||
NULL, //使用本进程的环境变量
|
||||
|
@ -207,7 +230,7 @@ static int test_fork()
|
|||
&pi);
|
||||
if (bRet)
|
||||
{
|
||||
//ä¸<EFBFBD>使用的å<EFBFBD>¥æŸ„最好关æŽ?
|
||||
//不使用的句柄最好关<EFBFBD>?
|
||||
CloseHandle(pi.hThread);
|
||||
CloseHandle(pi.hProcess);
|
||||
printf("new process id %d\n", pi.dwProcessId);
|
||||
|
@ -228,12 +251,12 @@ int DaemonizeMonitor::AddNewProcess(string path){
|
|||
STARTUPINFO si = {sizeof(si)};
|
||||
PROCESS_INFORMATION pi;
|
||||
si.dwFlags = STARTF_USESHOWWINDOW; //指定wShowWindow成员有效
|
||||
si.wShowWindow = TRUE; //æ¤æˆ<EFBFBD>员设为TRUEçš„è¯<EFBFBD>则显示新建进程的主窗å<EFBFBD>?
|
||||
si.wShowWindow = TRUE; //此成员设为TRUE的话则显示新建进程的主窗<EFBFBD>?
|
||||
BOOL bRet = CreateProcess(
|
||||
NULL, //不在此指定可执行文件的文件名
|
||||
(LPSTR)path.c_str(), //命令行å<EFBFBD>‚æ•?
|
||||
NULL, //默认进程安全�
|
||||
NULL, //默认进程安全�
|
||||
(LPSTR)path.c_str(), //命令行参<EFBFBD>?
|
||||
NULL, //默认进程安全<EFBFBD>?
|
||||
NULL, //默认进程安全<EFBFBD>?
|
||||
FALSE, //指定当前进程内句柄不可以被子进程继承
|
||||
CREATE_NEW_CONSOLE, //为新进程创建一个新的控制台窗口
|
||||
NULL, //使用本进程的环境变量
|
||||
|
@ -242,7 +265,7 @@ int DaemonizeMonitor::AddNewProcess(string path){
|
|||
&pi);
|
||||
if (bRet)
|
||||
{
|
||||
//ä¸<EFBFBD>使用的å<EFBFBD>¥æŸ„最好关æŽ?
|
||||
//不使用的句柄最好关<EFBFBD>?
|
||||
CloseHandle(pi.hThread);
|
||||
CloseHandle(pi.hProcess);
|
||||
|
||||
|
@ -289,7 +312,7 @@ int DaemonizeMonitor::StartMonitor(){
|
|||
}
|
||||
SetProcessPrivilege("SeDebugPrivilege", 0);
|
||||
if(!found){
|
||||
// 没找到该应用实例就é‡<EFBFBD>å<EFBFBD>¯åº”ç”?
|
||||
// 没找到该应用实例就重启应<EFBFBD>?
|
||||
auto it = m_path_process.begin();
|
||||
while (it != m_path_process.end())
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue