From 3613577677268a8c69fe1cf50de99e2ac434d025 Mon Sep 17 00:00:00 2001 From: Aaron Date: Fri, 30 Jan 2009 15:15:48 -0500 Subject: Better kill --- shell/ShellUtils.cpp | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) (limited to 'shell') diff --git a/shell/ShellUtils.cpp b/shell/ShellUtils.cpp index 5747e0d63be..0c5a8c7a0ee 100644 --- a/shell/ShellUtils.cpp +++ b/shell/ShellUtils.cpp @@ -299,11 +299,27 @@ v8::Handle< v8::Value > ResetDbpath( const v8::Arguments &a ) { } void killDb( int port ) { - assert( dbs.count( port ) == 1 ); + if( dbs.count( port ) != 1 ) { + cout << "No db started on port: " << port << endl; + return; + } + pid_t pid = dbs[ port ]; kill( pid, SIGTERM ); - int temp; - waitpid( pid, &temp, 0 ); + + boost::xtime xt; + boost::xtime_get(&xt, boost::TIME_UTC); + ++xt.sec; + int i = 0; + for( ; i < 5; ++i, ++xt.sec ) { + int temp; + if( waitpid( pid, &temp, WNOHANG ) != 0 ) + break; + boost::thread::sleep( xt ); + } + if ( i == 5 ) + kill( pid, SIGKILL ); + dbs.erase( port ); } -- cgit v1.2.1