|
@@ -143,6 +143,34 @@ proc * getChild(struct proc * p, int pid)
|
|
return procs->pids[pid];
|
|
return procs->pids[pid];
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+int assignpid(struct proc * proc)
|
|
|
|
+{
|
|
|
|
+ lock_acquire(proclock);
|
|
|
|
+
|
|
|
|
+ for (int i = procs->lastpid + 1; i <= PID_MAX; i++)
|
|
|
|
+ {
|
|
|
|
+ if (procs->pids[i] == 0)
|
|
|
|
+ {
|
|
|
|
+ proc->pid = i;
|
|
|
|
+ procs->lastpid = i;
|
|
|
|
+ lock_release(proclock);
|
|
|
|
+ return i;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (i == PID_MAX)
|
|
|
|
+ {
|
|
|
|
+ i = PID_MIN - 1;
|
|
|
|
+ continue;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (i == procs->lastpid)
|
|
|
|
+ {
|
|
|
|
+ lock_release(proclock);
|
|
|
|
+ return ENPROC;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+}
|
|
|
|
+
|
|
void delete_procs(procs * procs)
|
|
void delete_procs(procs * procs)
|
|
{
|
|
{
|
|
kfree(procs->pids);
|
|
kfree(procs->pids);
|
|
@@ -211,17 +239,21 @@ void proc_destroy(struct proc * proc)
|
|
threadarray_cleanup(&proc->p_threads);
|
|
threadarray_cleanup(&proc->p_threads);
|
|
spinlock_cleanup(&proc->p_lock);
|
|
spinlock_cleanup(&proc->p_lock);
|
|
|
|
|
|
|
|
+ lock_acquire(proclock);
|
|
|
|
+ procs->pids[proc->pid] = 0; // update available PIDs
|
|
|
|
+ lock_release(proclock);
|
|
kfree(proc->p_name);
|
|
kfree(proc->p_name);
|
|
kfree(proc);
|
|
kfree(proc);
|
|
|
|
|
|
#ifdef UW
|
|
#ifdef UW
|
|
/* decrement the process count */
|
|
/* decrement the process count */
|
|
- /* note: kproc is not included in the process count, but proc_destroy
|
|
|
|
|
|
+ /* note: kproc is not included as_copy in the process count, but proc_destroy
|
|
is never called on kproc (see KASSERT above), so we're OK to decrement
|
|
is never called on kproc (see KASSERT above), so we're OK to decrement
|
|
the proc_count unconditionally here */
|
|
the proc_count unconditionally here */
|
|
P(proc_count_mutex);
|
|
P(proc_count_mutex);
|
|
KASSERT(proc_count > 0);
|
|
KASSERT(proc_count > 0);
|
|
proc_count--;
|
|
proc_count--;
|
|
|
|
+
|
|
/* signal the kernel menu thread if the process count has reached zero */
|
|
/* signal the kernel menu thread if the process count has reached zero */
|
|
if (proc_count == 0)
|
|
if (proc_count == 0)
|
|
{
|
|
{
|
|
@@ -320,6 +352,7 @@ struct proc * proc_create_runprogram(const char * name)
|
|
are created using a call to proc_create_runprogram */
|
|
are created using a call to proc_create_runprogram */
|
|
P(proc_count_mutex);
|
|
P(proc_count_mutex);
|
|
proc_count++;
|
|
proc_count++;
|
|
|
|
+ assignpid(struct proc * proc);
|
|
V(proc_count_mutex);
|
|
V(proc_count_mutex);
|
|
#endif // UW
|
|
#endif // UW
|
|
|
|
|