Reverting back to old linking code

This commit is contained in:
Dan Snyder 2025-01-14 19:42:12 -05:00
parent 3960919efe
commit 46e5fca147

View File

@ -110,32 +110,29 @@ int resetVisits(Process *head) {
void linkFamily(Process *head) { void linkFamily(Process *head) {
int orphans = resetVisits(head); int orphans = 1;
while (orphans) { while (orphans) {
Process *cur, *parent = head; orphans = 0;
// get next unvisited node Process *current = head;
while (parent != NULL && parent->visited) parent = parent->next; // while on an actual process node, and it has a parent link or doesn't need a parent link (kernel)
while (current != NULL && (current->parent != NULL || current->ppid == current->pid)) current = current->next;
if (current == NULL) break;
orphans = 1;
if (parent == NULL) { // sanity check Process *parent = head;
printf("Error: Found %d orphan process(es):\n", orphans); while (parent != NULL && parent->pid != current->ppid) parent = parent->next;
break; if (parent == NULL) {
printf("Found orphan process: %d\n", current->pid);
current->ppid = -1;
continue;
} }
parent->visited = 1; // We have a parent and a child ready to be united
current->parent = parent;
// Search for children Process **placement = &(parent->child);
for (cur = head; cur != NULL; cur = cur->next) { while ((*placement) != NULL) placement = &((*placement)->sibling);
if (cur->ppid != parent->pid) continue; *placement = current;
// We have a parent and child ready to be united
orphans--;
cur->parent = parent;
// place child amongst siblings, if any are present
Process **placement = &(parent->child);
while ((*placement) != NULL) placement = &((*placement)->sibling);
*placement = cur;
}
} }
} }
@ -272,7 +269,7 @@ char *readProcesses(char *procdir) {
if (first < '0' || first > '9') continue; if (first < '0' || first > '9') continue;
if (cur->visited) { if (cur->visited) {
// get new process node if necessary // get new process if necessary
prev = cur; prev = cur;
cur->next = calloc(1, sizeof(Process)); cur->next = calloc(1, sizeof(Process));
cur = cur->next; cur = cur->next;