2019-11-08 in class
This commit is contained in:
parent
d5928cbe06
commit
0de237cd78
2 changed files with 15 additions and 9 deletions
|
@ -67,7 +67,6 @@ int add_from_file(struct processes* ps, const char* filename) {
|
|||
// printf("%d %d %s %d %f %ld %ld %ld %s\n", p.pid, p.ppid,
|
||||
// p.user, p.priority, p.cpu, p.resident_size, p.size,
|
||||
// p.virtual_size, p.command);
|
||||
printf("%ld\n", ps->size);
|
||||
if (ps->size == ps->capacity) {
|
||||
ps->capacity *= 2;
|
||||
struct process* new_procs = realloc(ps->procs,
|
||||
|
@ -117,16 +116,17 @@ struct query_result* search(struct processes* ps, const struct query* q) {
|
|||
add = add && (q->rss == 0 || (q->rss < 0 &&
|
||||
(q->rss * -1) < p->resident_size) ||
|
||||
(q->rss > 0 && q->rss == p->resident_size));
|
||||
add = (q->size == 0 || (q->size < 0 &&
|
||||
add = add && (q->size == 0 || (q->size < 0 &&
|
||||
(q->size * -1) < p->size) ||
|
||||
(q->size > 0 && q->size == p->size));
|
||||
add = (q->vsize == 0 || (q->vsize < 0 &&
|
||||
add = add && (q->vsize == 0 || (q->vsize < 0 &&
|
||||
(q->vsize * -1) < p->virtual_size) ||
|
||||
(q->vsize > 0 && q->vsize == p->virtual_size));
|
||||
add = (q->cpu_usage == 0 || (q->cpu_usage < 0 &&
|
||||
add = add && (q->cpu_usage == 0 || (q->cpu_usage < 0 &&
|
||||
q->cpu_usage * -1 < p->cpu) ||
|
||||
(q->cpu_usage > 0 && q->cpu_usage == p->cpu));
|
||||
|
||||
|
||||
if (add) {
|
||||
res->procs[res->size] = p;
|
||||
res->size++;
|
||||
|
@ -144,15 +144,21 @@ struct query_result* search(struct processes* ps, const struct query* q) {
|
|||
}
|
||||
}
|
||||
|
||||
if(res->size == 0) {
|
||||
free(res->procs);
|
||||
free(res);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
struct query_result* next(struct query_result* q) {
|
||||
q->i++;
|
||||
if (q->i == q->size) {
|
||||
terminate_query(q);
|
||||
return NULL;
|
||||
}
|
||||
q->i++;
|
||||
return q;
|
||||
}
|
||||
|
||||
|
|
Reference in a new issue