This repository has been archived by the owner on Mar 15, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
Added watchdog #3
Open
octopuscabbage
wants to merge
7
commits into
master
Choose a base branch
from
commander_update
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
978a847
started work on watchdog functor
octopuscabbage 0b49079
Finished watchdog
octopuscabbage 17058f3
Finished watchdog
octopuscabbage b9258c4
Merge branch 'commander_update' of https://github.com/geekygirlsarah/…
octopuscabbage ece2e52
Added unistd.h back in
octopuscabbage dfe6bc6
Fixed error in thread call
octopuscabbage e2cc49a
Fixed an error in watchdog
octopuscabbage File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
#include "watchdog.h" | ||
#include <unistd.h> | ||
#include <stdio.h> | ||
#include <sstream> | ||
#include <thread> | ||
#include <chrono> | ||
using std::stringstream; | ||
|
||
void WatchDog::execute_pkill(string name){ | ||
stringstream ss; | ||
ss << "pkill " << name; | ||
FILE * f = popen(ss.str().c_str(),"r"); | ||
pclose(f); | ||
} | ||
|
||
void WatchDog::tick(){ | ||
amountCalled++; | ||
} | ||
|
||
void WatchDog::operator()(string binaryName){ | ||
amountCalled = 0; | ||
while(amountCalled < checkAmount){ | ||
tick(); | ||
std::this_thread::sleep_for(std::chrono::seconds(seconds_to_sleep)); | ||
} | ||
execute_pkill(binaryName); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
#include <string> | ||
#include <unistd.h> | ||
#include <signal.h> | ||
#include <thread> | ||
#include <map> | ||
#include <stdio.h> | ||
using std::map; | ||
using std::string; | ||
|
||
#ifndef WATCHDOG_H | ||
#define WATCHDOG_H | ||
/** | ||
* Watch dog is a functor object that should be called as such | ||
* WatchDog watch; | ||
* std::thread(watch,binaryName); | ||
*/ | ||
class WatchDog{ | ||
string name; | ||
int amountCalled; | ||
int checkAmount; /*<The time in near-seconds for the thread to be alive before it's killed */ | ||
const int seconds_to_sleep = 1; | ||
//Tick through each process updating the amount of times it's been called in call_map and kills it if it's been checked checkAmount times | ||
void tick(); | ||
void execute_pkill(string name); | ||
|
||
public: | ||
WatchDog(){checkAmount=1000;} | ||
WatchDog(int amountOfTicksBeforeKilled){checkAmount=amountOfTicksBeforeKilled;} | ||
void operator()(string binaryName); | ||
|
||
}; | ||
#endif | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this requires c++11