library/src/filesystem/BP-Filesystem.cc
// Attempts to stop a running program (killing it) provided a valid fdset with
// a valid pid.
Attempts to stop a running program (killing it) provided a valid fdset with
a valid pid.
Attempts to stop a running program ( killing it ) provided a valid fdset with a valid pid .
BP_ERROR_T BP_FExecKillApplication(P_BP_FDSET app_to_kill)
{
	if(!app_to_kill)
		return ERR_FAILURE;
	if(!app_to_kill->pid)
		return ERR_FAILURE;
	if(kill(app_to_kill->pid, SIGKILL))
		return ERR_FAILURE;
	waitpid(-1, NULL, WNOHANG);
	BP_BOOL still_running = BP_FALSE;
	do
	{
		still_running = BP_FExecApplicationStillRunning(app_to_kill) ? BP_TRUE : BP_FALSE;
		if(still_running)
		{
			sleep(1);
			BP_FExecKillApplication(app_to_kill);
		}
	} while(still_running);
	app_to_kill->oldt.c_lflag |= ECHO | ECHONL | ICANON;
	tcsetattr(STDIN_FILENO, TCSAFLUSH, &app_to_kill->oldt);
	return ERR_SUCCESS;
}
BP_ERROR_T BP_FExecKillApplication ( P_BP_FDSET app_to_kill ) { if ( ! app_to_kill ) return ERR_FAILURE ; if ( ! app_to_kill -> pid ) return ERR_FAILURE ; if ( kill ( app_to_kill -> pid , SIGKILL ) ) return ERR_FAILURE ; waitpid ( -1 , NULL , WNOHANG ) ; BP_BOOL still_running = BP_FALSE ; do { still_running = BP_FExecApplicationStillRunning ( app_to_kill ) ? BP_TRUE : BP_FALSE ; if ( still_running ) { sleep ( 1 ) ; BP_FExecKillApplication ( app_to_kill ) ; } } while ( still_running ) ; app_to_kill -> oldt . c_lflag |= ECHO | ECHONL | ICANON ; tcsetattr ( STDIN_FILENO , TCSAFLUSH , & app_to_kill -> oldt ) ; return ERR_SUCCESS ; }
Attempts to stop a running program (killing it) provided a valid fdset with
a valid pid.
Attempts to stop a running program ( killing it ) provided a valid fdset with a valid pid .
// if we have no app to kill, exit // attempt to kill the app (error is non-zero) // wait here to cleanup zombies if they exist // set flag to run still running check // check if application is still running // if it's still running, send another kill signal after sleeping 1 second // Restore initial properties of STDIN to the old term // return indicating success after kill signal is sent