Fixed slow-working Util::Procs terminate handler.
This commit is contained in:
parent
07a4b61142
commit
6f7b300bf5
1 changed files with 39 additions and 20 deletions
|
@ -25,47 +25,66 @@ std::map<pid_t, Util::TerminationNotifier> Util::Procs::exitHandlers;
|
||||||
bool Util::Procs::handler_set = false;
|
bool Util::Procs::handler_set = false;
|
||||||
|
|
||||||
/// Called at exit of any program that used a Start* function.
|
/// Called at exit of any program that used a Start* function.
|
||||||
/// Waits up to 2.5 seconds, then sends SIGINT signal to all managed processes.
|
/// Waits up to 1 second, then sends SIGINT signal to all managed processes.
|
||||||
/// After that waits up to 10 seconds for children to exit, then sends SIGKILL to
|
/// After that waits up to 5 seconds for children to exit, then sends SIGKILL to
|
||||||
/// all remaining children. Waits one more second for cleanup to finish, then exits.
|
/// all remaining children. Waits one more second for cleanup to finish, then exits.
|
||||||
void Util::Procs::exit_handler(){
|
void Util::Procs::exit_handler(){
|
||||||
int waiting = 0;
|
int waiting = 0;
|
||||||
while ( !plist.empty()){
|
std::map<pid_t, std::string> listcopy = plist;
|
||||||
Util::sleep(100);
|
std::map<pid_t, std::string>::iterator it;
|
||||||
if (++waiting > 25){
|
|
||||||
break;
|
//wait up to 1 second for applications to shut down
|
||||||
|
while ( !listcopy.empty() && waiting <= 50){
|
||||||
|
for (it = listcopy.begin(); it != listcopy.end(); it++){
|
||||||
|
if (kill(( *it).first, 0) == 0){
|
||||||
|
Util::sleep(20);
|
||||||
|
++waiting;
|
||||||
|
}else{
|
||||||
|
listcopy.erase(it);
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( !plist.empty()){
|
//send sigint to all remaining
|
||||||
std::map<pid_t, std::string> listcopy = plist;
|
if ( !listcopy.empty()){
|
||||||
std::map<pid_t, std::string>::iterator it;
|
|
||||||
for (it = listcopy.begin(); it != listcopy.end(); it++){
|
for (it = listcopy.begin(); it != listcopy.end(); it++){
|
||||||
kill(( *it).first, SIGINT);
|
kill(( *it).first, SIGINT);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
waiting = 0;
|
waiting = 0;
|
||||||
while ( !plist.empty()){
|
//wait up to 5 seconds for applications to shut down
|
||||||
Util::sleep(200);
|
while ( !listcopy.empty() && waiting <= 50){
|
||||||
if (++waiting > 25){
|
for (it = listcopy.begin(); it != listcopy.end(); it++){
|
||||||
break;
|
if (kill(( *it).first, 0) == 0){
|
||||||
|
Util::sleep(100);
|
||||||
|
++waiting;
|
||||||
|
}else{
|
||||||
|
listcopy.erase(it);
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//send sigkill to all remaining
|
||||||
if ( !plist.empty()){
|
if ( !plist.empty()){
|
||||||
std::map<pid_t, std::string> listcopy = plist;
|
|
||||||
std::map<pid_t, std::string>::iterator it;
|
|
||||||
for (it = listcopy.begin(); it != listcopy.end(); it++){
|
for (it = listcopy.begin(); it != listcopy.end(); it++){
|
||||||
kill(( *it).first, SIGKILL);
|
kill(( *it).first, SIGKILL);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
waiting = 0;
|
waiting = 0;
|
||||||
while ( !plist.empty()){
|
//wait up to 1 second for applications to shut down
|
||||||
Util::sleep(100);
|
while ( !listcopy.empty() && waiting <= 50){
|
||||||
if (++waiting > 10){
|
for (it = listcopy.begin(); it != listcopy.end(); it++){
|
||||||
break;
|
if (kill(( *it).first, 0) == 0){
|
||||||
|
Util::sleep(20);
|
||||||
|
++waiting;
|
||||||
|
}else{
|
||||||
|
listcopy.erase(it);
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue