library/src/blockclass/subclasses/command_line_tools/BP_CommandLineToolBase.cc
BP_ERROR_T BP_CommandLineToolBase::postExecutionCleanup()
{

	// close file descriptors
	close(this->fdSet->stderr[0]);
	close(this->fdSet->stderr[1]);
	close(this->fdSet->stdin[0]);
	close(this->fdSet->stdin[1]);
	close(this->fdSet->stdout[0]);
	close(this->fdSet->stdout[1]);

	// run kill loop
	do
	{

		if(!this->fdSet->pid || this->fdSet->pid == (pid_t) -1 )
			break;

		// attempt to wait on any pid (frees any possible zombies)
		waitpid(-1,NULL,WNOHANG);

		// update the application snapshot
		this->app_mon->updateSnapshot();

		// search for the process
		this->app_mon->searchProcesses(NULL, NULL, this->fdSet->pid);

		// If our process doesn't exist, we can exit ok without forcible
		// kill.
		if(!this->app_mon->process_search_indexes_n)
			break;

		// At this point, we've confirmed that our application still exists, so we must
		// kill it forcibly

		// create kill buffer
		char kill_buff[128];

		// zero out the buffer
		memset(&kill_buff, 0x00, sizeof(kill_buff));

		// SAFELY create kill buffer
		sprintf((char *) &kill_buff, "kill -9 %u", this->fdSet->pid);

		printf("\n [+] Running Kill: %s", kill_buff);

		// use system command shell to kill the process
		system(kill_buff);

		// sleep before trying again (prevents kill insanity)
		sleep(1);

	} while (this->app_mon->process_search_indexes_n);

	// return indicating success
	return ERR_SUCCESS;
}
// Run this after execution to clean up any data stored in the class.
Run this after execution to clean up any data stored in the class.
Run this after execution to clean up any data stored in the class .
BP_ERROR_T BP_CommandLineToolBase::postExecutionCleanup()
{
	close(this->fdSet->stderr[0]);
	close(this->fdSet->stderr[1]);
	close(this->fdSet->stdin[0]);
	close(this->fdSet->stdin[1]);
	close(this->fdSet->stdout[0]);
	close(this->fdSet->stdout[1]);
	do
	{
		if(!this->fdSet->pid || this->fdSet->pid == (pid_t) -1 )
			break;
		waitpid(-1,NULL,WNOHANG);
		this->app_mon->updateSnapshot();
		this->app_mon->searchProcesses(NULL, NULL, this->fdSet->pid);
		if(!this->app_mon->process_search_indexes_n)
			break;
		char kill_buff[128];
		memset(&kill_buff, 0x00, sizeof(kill_buff));
		sprintf((char *) &kill_buff, "kill -9 %u", this->fdSet->pid);
		printf("\n [+] Running Kill: %s", kill_buff);
		system(kill_buff);
		sleep(1);
	} while (this->app_mon->process_search_indexes_n);
	return ERR_SUCCESS;
}
BP_ERROR_T BP_CommandLineToolBase :: postExecutionCleanup ( ) { close ( this -> fdSet -> stderr [ 0 ] ) ; close ( this -> fdSet -> stderr [ 1 ] ) ; close ( this -> fdSet -> stdin [ 0 ] ) ; close ( this -> fdSet -> stdin [ 1 ] ) ; close ( this -> fdSet -> stdout [ 0 ] ) ; close ( this -> fdSet -> stdout [ 1 ] ) ; do { if ( ! this -> fdSet -> pid || this -> fdSet -> pid == ( pid_t ) - 1 ) break ; waitpid ( -1 , NULL , WNOHANG ) ; this -> app_mon -> updateSnapshot ( ) ; this -> app_mon -> searchProcesses ( NULL , NULL , this -> fdSet -> pid ) ; if ( ! this -> app_mon -> process_search_indexes_n ) break ; char kill_buff [ 128 ] ; memset ( & kill_buff , 0x00 , sizeof ( kill_buff ) ) ; sprintf ( ( char * ) & kill_buff , " " , this -> fdSet -> pid ) ; printf ( " \n " , kill_buff ) ; system ( kill_buff ) ; sleep ( 1 ) ; } while ( this -> app_mon -> process_search_indexes_n ) ; return ERR_SUCCESS ; }
Run this after execution to clean up any data stored in the class.
Run this after execution to clean up any data stored in the class .
// close file descriptors // run kill loop // attempt to wait on any pid (frees any possible zombies) // update the application snapshot // search for the process // If our process doesn't exist, we can exit ok without forcible // kill. // At this point, we've confirmed that our application still exists, so we must // kill it forcibly // create kill buffer // zero out the buffer // SAFELY create kill buffer // use system command shell to kill the process // sleep before trying again (prevents kill insanity) // return indicating success