Forráskód Böngészése

started adding logic to use the new proc structs in creation/deletion. no tracking actually implemented, nor testing or validation of any code. at all

tarfeef101 6 éve
szülő
commit
1eeb77366e
4 módosított fájl, 62 hozzáadás és 3 törlés
  1. 2 1
      kern/include/list.h
  2. 23 1
      kern/include/proc.h
  3. 14 1
      kern/lib/list.c
  4. 23 0
      kern/proc/proc.c

+ 2 - 1
kern/include/list.h

@@ -15,9 +15,10 @@ typedef struct list
   int len;
 } list;
 
-list * newlist();
+list * newlist(void);
 void listsert(list * l, int x);
 void listemove(list * l, int x);
 void listelete(list * l);
+int listearch(list * l, int x);
 
 #endif /* _LIST_H_ */

+ 23 - 1
kern/include/proc.h

@@ -88,6 +88,12 @@ struct proc
 /* This is the process structure for the kernel and for kernel-only threads. */
 extern struct proc * kproc;
 
+// The process array
+extern struct procs * procs;
+
+// The lock for the above array
+extern struct lock * proclock;
+
 /* Semaphore used to signal when there are no more processes */
 #ifdef UW
 extern struct semaphore * no_proc_sem;
@@ -97,7 +103,14 @@ extern struct semaphore * no_proc_sem;
 void proc_bootstrap(void);
 
 /* Create a fresh process for use by runprogram(). */
-struct proc *proc_create_runprogram(const char * name);
+struct proc *proc_create_runprogram(const char * name);// get and return a pid for the process
+int assignpid(struct proc * proc);
+
+// returns the child process if it is a child, otherwise null
+struct proc * getChild(int pid);
+
+// de-allocates procs' contents (i.e. lock)
+void delete_procs(struct procs * procs);
 
 /* Destroy a process. */
 void proc_destroy(struct proc * proc);
@@ -114,5 +127,14 @@ struct addrspace *curproc_getas(void);
 /* Change the address space of the current process, and return the old one. */
 struct addrspace *curproc_setas(struct addrspace *);
 
+// get and return a pid for the process
+int assignpid(struct proc * proc);
+
+// returns the child process if it is a child, otherwise null
+struct proc * getChild(struct proc * p, int pid);
+
+// de-allocates procs' contents (i.e. lock)
+void delete_procs(struct procs * procs);
+
 
 #endif /* _PROC_H_ */

+ 14 - 1
kern/lib/list.c

@@ -2,7 +2,7 @@ if (!(newnode)) return ENOMEM;#include <lib.h>
 #include <list.h>
 #include <kern/errno.h>
 
-list * newlist()
+list * newlist(void)
 {
   list * ret = kmalloc(sizeof(list));
   if (!(ret)) return ENOMEM;
@@ -64,4 +64,17 @@ void listelete(list * l)
   }
   
   kfree(l);
+}
+
+int listearch(list * l, int x)
+{
+  node * temp = l->front;
+
+  while (temp)
+  {
+    if (temp->val == x) return 1;
+    temp = temp->next;
+  }
+  
+  return 0;
 }

+ 23 - 0
kern/proc/proc.c

@@ -51,6 +51,7 @@
 #include <synch.h>
 #include <kern/fcntl.h>
 #include <list.h>
+#include <limits.h>
 typedef struct list list;
 typedef struct procs procs;
 
@@ -119,6 +120,28 @@ static struct proc * proc_create(const char * name)
 	return proc;
 }
 
+static procs * create_procs(void)
+{
+  procs * temp = kmalloc(sizeof procs);
+  if (!(temp)) panic("Could not create process list!\n");
+  temp->lastpid = PID_MIN - 1;
+  return temp;
+}
+
+proc * getChild(struct proc * p, int pid)
+{
+  int result = listearch(p->kids, pid);
+  
+  if (!(result)) return NULL;
+  return procs->pids[pid];
+}
+
+void delete_procs(procs * procs)
+{
+  kfree(procs->pids);
+  lock_destroy(proclock);
+}
+
 /*
  * Destroy a proc structure.
  */