aboutsummaryrefslogtreecommitdiffstats
path: root/src/process_group.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/process_group.c')
-rw-r--r--src/process_group.c76
1 files changed, 36 insertions, 40 deletions
diff --git a/src/process_group.c b/src/process_group.c
index b8b1155..2afef71 100644
--- a/src/process_group.c
+++ b/src/process_group.c
@@ -2,71 +2,67 @@
#include <string.h>
#include <stdlib.h>
#include <limits.h>
+
+#include "process_iterator.h"
#include "process_group.h"
#include "list.h"
-int init_process_monitor(struct process_monitor *monitor, int target_pid, int ignore_children)
+int init_process_group(struct process_group *pgroup, int target_pid, int include_children)
{
//hashtable initialization
- memset(&monitor->proctable, 0, sizeof(monitor->proctable));
- monitor->target_pid = target_pid;
- monitor->ignore_children = ignore_children;
+ memset(&pgroup->proctable, 0, sizeof(pgroup->proctable));
+ pgroup->target_pid = target_pid;
+ pgroup->include_children = include_children;
+ pgroup->proclist = (struct list*)malloc(sizeof(struct list));
+ return 0;
+}
+
+int close_process_group(struct process_group *pgroup)
+{
+ int i;
+ int size = sizeof(pgroup->proctable) / sizeof(struct process*);
+ for (i=0; i<size; i++) {
+ if (pgroup->proctable[i] != NULL) {
+ //free() history for each process
+ destroy_list(pgroup->proctable[i]);
+ free(pgroup->proctable[i]);
+ pgroup->proctable[i] = NULL;
+ }
+ }
+ free(pgroup->proclist);
+ pgroup->proclist = NULL;
return 0;
}
-struct list* get_process_list(struct process_monitor *monitor)
+void update_process_group(struct process_group *pgroup)
{
struct process_iterator it;
struct process process;
- init_process_iterator(&it);
- while (read_next_process(&it, &process) != -1)
+ struct process_filter filter;
+ filter.pid = pgroup->target_pid;
+ filter.include_children = pgroup->include_children;
+ init_process_iterator(&it, &filter);
+ while (get_next_process(&it, &process) != -1)
{
- if (monitor->ignore_children && process.pid != monitor->target_pid) continue;
printf("Read process %d\n", process.pid);
printf("Parent %d\n", process.ppid);
printf("Starttime %d\n", process.starttime);
printf("CPU time %d\n", process.cputime);
-
int hashkey = pid_hashfn(process.pid + process.starttime);
- if (monitor->proctable[hashkey] == NULL)
+ if (pgroup->proctable[hashkey] == NULL)
{
-
- if (is_ancestor(pid, ppid))
- struct process *ancestor = NULL;
- while((ancestor=seek_process(f, ppid))==NULL) {
- ppid = getppid_of(ppid);
- }
-
-
//empty bucket
- monitor->proctable[hashkey] = malloc(sizeof(struct list));
+ pgroup->proctable[hashkey] = malloc(sizeof(struct list));
struct process *new_process = malloc(sizeof(struct process));
memcpy(new_process, &process, sizeof(struct process));
- init_list(monitor->proctable[hashkey], 4);
- add_elem(monitor->proctable[hashkey], new_process);
+ init_list(pgroup->proctable[hashkey], 4);
+ add_elem(pgroup->proctable[hashkey], new_process);
}
else
{
-
+ //existing bucket
+
}
}
close_process_iterator(&it);
-
- return NULL;
}
-
-int close_process_monitor(struct process_monitor *monitor)
-{
- int i;
- int size = sizeof(monitor->proctable) / sizeof(struct process*);
- for (i=0; i<size; i++) {
- if (monitor->proctable[i] != NULL) {
- //free() history for each process
- destroy_list(monitor->proctable[i]);
- free(monitor->proctable[i]);
- monitor->proctable[i] = NULL;
- }
- }
- monitor->target_pid = 0;
- return 0;
-} \ No newline at end of file
Un proyecto texto-plano.xyz