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