-
Notifications
You must be signed in to change notification settings - Fork 0
/
kernel_proc.h
105 lines (73 loc) · 2.87 KB
/
kernel_proc.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#ifndef __KERNEL_PROC_H
#define __KERNEL_PROC_H
/**
@file kernel_proc.h
@brief The process table and process management.
@defgroup proc Processes
@ingroup kernel
@brief The process table and process management.
This file defines the PCB structure and basic helpers for
process access.
@{
*/
#include "tinyos.h"
#include "kernel_sched.h"
/**
@brief PID state
A PID can be either free (no process is using it), ALIVE (some running process is
using it), or ZOMBIE (a zombie process is using it).
*/
typedef enum pid_state_e {
FREE, /**< @brief The PID is free and available */
ALIVE, /**< @brief The PID is given to a process */
ZOMBIE /**< @brief The PID is held by a zombie */
} pid_state;
/**
@brief Process Control Block.
This structure holds all information pertaining to a process.
*/
typedef struct process_control_block {
pid_state pstate; /**< @brief The pid state for this PCB */
PCB* parent; /**< @brief Parent's pcb. */
int exitval; /**< @brief The exit value of the process */
rlnode thread_list; /* The list of threads of the process*/
uint thread_count; /* The number of threads in the process*/
Task main_task; /**< @brief The main thread's function */
int argl; /**< @brief The main thread's argument length */
void* args; /**< @brief The main thread's argument string */
rlnode children_list; /**< @brief List of children */
rlnode exited_list; /**< @brief List of exited children */
rlnode children_node; /**< @brief Intrusive node for @c children_list */
rlnode exited_node; /**< @brief Intrusive node for @c exited_list */
CondVar child_exit; /**< @brief Condition variable for @c WaitChild.
This condition variable is broadcast each time a child
process terminates. It is used in the implementation of
@c WaitChild() */
FCB* FIDT[MAX_FILEID]; /**< @brief The fileid table of the process */
} PCB;
/**
@brief Initialize the process table.
This function is called during kernel initialization, to initialize
any data structures related to process creation.
*/
void initialize_processes();
/**
@brief Get the PCB for a PID.
This function will return a pointer to the PCB of
the process with a given PID. If the PID does not
correspond to a process, the function returns @c NULL.
@param pid the pid of the process
@returns A pointer to the PCB of the process, or NULL.
*/
PCB* get_pcb(Pid_t pid);
/**
@brief Get the PID of a PCB.
This function will return the PID of the process
whose PCB is pointed at by @c pcb. If the pcb does not
correspond to a process, the function returns @c NOPROC.
@param pcb the pcb of the process
@returns the PID of the process, or NOPROC.
*/
Pid_t get_pid(PCB* pcb);
/** @} */
#endif