2020-03-23 15:58:48 +01:00
|
|
|
#include <kernel/scheduler.h>
|
|
|
|
#include <kernel/util/atomic.h>
|
2019-12-29 16:39:30 +01:00
|
|
|
|
2020-03-23 15:58:48 +01:00
|
|
|
struct process *process_get(pid_t pid)
|
2019-12-29 16:39:30 +01:00
|
|
|
{
|
2020-03-23 15:58:48 +01:00
|
|
|
extern struct process *proc_table;
|
|
|
|
struct process *proc;
|
2019-12-29 16:39:30 +01:00
|
|
|
|
|
|
|
// Check error
|
2020-03-23 15:58:48 +01:00
|
|
|
if (pid <= 0)
|
2019-12-29 16:39:30 +01:00
|
|
|
return (NULL);
|
|
|
|
|
2020-03-23 15:58:48 +01:00
|
|
|
// Start atomic operation
|
|
|
|
atomic_start();
|
2020-02-05 21:09:39 +01:00
|
|
|
|
2020-03-23 15:58:48 +01:00
|
|
|
// Proess table walk
|
|
|
|
proc = proc_table;
|
|
|
|
while (proc != NULL)
|
2020-02-05 21:09:39 +01:00
|
|
|
{
|
2020-03-23 15:58:48 +01:00
|
|
|
// 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);
|
2020-02-05 21:09:39 +01:00
|
|
|
}
|
2020-03-23 15:58:48 +01:00
|
|
|
|
|
|
|
// Stop atomic operation
|
|
|
|
atomic_stop();
|
|
|
|
return (NULL);
|
2020-02-05 21:09:39 +01:00
|
|
|
}
|