39 lines
630 B
C
39 lines
630 B
C
#include <kernel/scheduler.h>
|
|
#include <kernel/util/atomic.h>
|
|
|
|
struct process *process_get(pid_t pid)
|
|
{
|
|
extern struct process *proc_table;
|
|
struct process *proc;
|
|
|
|
// Check error
|
|
if (pid <= 0)
|
|
return (NULL);
|
|
|
|
// Start atomic operation
|
|
atomic_start();
|
|
|
|
// Proess table walk
|
|
proc = proc_table;
|
|
while (proc != NULL)
|
|
{
|
|
// Check target process
|
|
if (proc->pid != pid) {
|
|
proc = proc->next;
|
|
continue;
|
|
}
|
|
|
|
// Check if the process is alive
|
|
if (proc->status == PROC_DEAD)
|
|
proc = NULL;
|
|
|
|
// Stop atomic operations
|
|
atomic_stop();
|
|
return (proc);
|
|
}
|
|
|
|
// Stop atomic operation
|
|
atomic_stop();
|
|
return (NULL);
|
|
}
|