Process: Add cleanup logic for unused processes and introduce a "keep" flag for special processes
This commit is contained in:
@@ -83,10 +83,12 @@ float togbps(u_int64_t bytes) { return (((double)bytes) / PERIOD) / GB; }
|
|||||||
|
|
||||||
void process_init() {
|
void process_init() {
|
||||||
unknowntcp = new Process(0, "", "unknown TCP");
|
unknowntcp = new Process(0, "", "unknown TCP");
|
||||||
|
unknowntcp->keep = true;
|
||||||
processes = new ProcList(unknowntcp, NULL);
|
processes = new ProcList(unknowntcp, NULL);
|
||||||
|
|
||||||
if (catchall) {
|
if (catchall) {
|
||||||
unknownudp = new Process(0, "", "unknown UDP");
|
unknownudp = new Process(0, "", "unknown UDP");
|
||||||
|
unknownudp->keep = true;
|
||||||
processes = new ProcList(unknownudp, processes);
|
processes = new ProcList(unknownudp, processes);
|
||||||
// unknownip = new Process (0, "", "unknown IP");
|
// unknownip = new Process (0, "", "unknown IP");
|
||||||
// processes = new ProcList (unknownip, processes);
|
// processes = new ProcList (unknownip, processes);
|
||||||
@@ -449,4 +451,29 @@ void remove_timed_out_processes() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void garbage_collect_processes() { garbage_collect_inodeproc(); }
|
void garbage_collect_processes()
|
||||||
|
{
|
||||||
|
garbage_collect_inodeproc();
|
||||||
|
|
||||||
|
ProcList *previousproc = NULL;
|
||||||
|
ProcList *curProc = processes;
|
||||||
|
while (curProc != NULL) {
|
||||||
|
Process *curProcVal = curProc->getVal();
|
||||||
|
if (curProcVal->connections.empty() && curProcVal->keep == false) {
|
||||||
|
ProcList *toDelete = curProc;
|
||||||
|
if (previousproc == NULL) {
|
||||||
|
processes = curProc->next;
|
||||||
|
}else
|
||||||
|
{
|
||||||
|
previousproc->next = curProc->next;
|
||||||
|
}
|
||||||
|
curProc = curProc->next;
|
||||||
|
delete curProcVal;
|
||||||
|
delete toDelete;
|
||||||
|
} else {
|
||||||
|
previousproc = curProc;
|
||||||
|
curProc = curProc->next;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|||||||
@@ -79,6 +79,7 @@ public:
|
|||||||
rcvd_by_closed_bytes = 0;
|
rcvd_by_closed_bytes = 0;
|
||||||
sent_last_reported = 0;
|
sent_last_reported = 0;
|
||||||
rcvd_last_reported = 0;
|
rcvd_last_reported = 0;
|
||||||
|
keep = false;
|
||||||
}
|
}
|
||||||
void check() { assert(pid >= 0); }
|
void check() { assert(pid >= 0); }
|
||||||
|
|
||||||
@@ -117,6 +118,8 @@ public:
|
|||||||
|
|
||||||
unsigned long getInode() { return inode; }
|
unsigned long getInode() { return inode; }
|
||||||
|
|
||||||
|
bool keep;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
const unsigned long inode;
|
const unsigned long inode;
|
||||||
uid_t uid;
|
uid_t uid;
|
||||||
|
|||||||
Reference in New Issue
Block a user