pub struct Process {Show 28 fields
pub pid: ProcessId,
pub parent: Option<ProcessId>,
pub name: String,
pub state: AtomicU32,
pub priority: Mutex<ProcessPriority>,
pub memory_space: Mutex<VirtualAddressSpace>,
pub capability_space: Mutex<CapabilitySpace>,
pub file_table: Mutex<FileTable>,
pub threads: Mutex<BTreeMap<ThreadId, Thread>>,
pub ipc_endpoints: Mutex<BTreeMap<EndpointId, CapabilityId>>,
pub children: Mutex<Vec<ProcessId>>,
pub exit_code: AtomicU32,
pub cpu_time: AtomicU64,
pub memory_stats: MemoryStats,
pub created_at: u64,
pub uid: u32,
pub gid: u32,
pub pgid: AtomicU64,
pub sid: AtomicU64,
pub env_vars: Mutex<BTreeMap<String, String>>,
pub signal_handlers: Mutex<[u64; 32]>,
pub pending_signals: AtomicU64,
pub signal_mask: AtomicU64,
pub umask: AtomicU32,
pub tls_fs_base: AtomicU64,
pub container_id: AtomicU64,
pub clear_child_tid: AtomicU64,
pub robust_list_head: AtomicU64,
}Expand description
Process Control Block
Fields§
§pid: ProcessIdProcess ID
parent: Option<ProcessId>Parent process ID (None for init)
name: StringProcess name
state: AtomicU32Process state
priority: Mutex<ProcessPriority>Priority
memory_space: Mutex<VirtualAddressSpace>Virtual address space
capability_space: Mutex<CapabilitySpace>Capability space
file_table: Mutex<FileTable>File descriptor table
threads: Mutex<BTreeMap<ThreadId, Thread>>Threads in this process
ipc_endpoints: Mutex<BTreeMap<EndpointId, CapabilityId>>IPC endpoints owned by this process
children: Mutex<Vec<ProcessId>>Child processes
exit_code: AtomicU32Exit code (set when process exits)
cpu_time: AtomicU64CPU time used (in microseconds)
memory_stats: MemoryStatsMemory usage statistics
created_at: u64Creation timestamp
uid: u32User ID (for future use)
gid: u32Group ID (for future use)
pgid: AtomicU64Process group ID (initialized to pid)
sid: AtomicU64Session ID (initialized to pid)
env_vars: Mutex<BTreeMap<String, String>>Environment variables (populated during exec, inherited on fork)
signal_handlers: Mutex<[u64; 32]>Signal handlers (signal number -> handler action) 0 = default, 1 = ignore, other values = handler address
pending_signals: AtomicU64Pending signals bitmap
signal_mask: AtomicU64Signal mask (blocked signals)
umask: AtomicU32File creation mask (umask). Default 0o022.
tls_fs_base: AtomicU64TLS FS_BASE address for x86_64 (Thread-Local Storage). Set by exec_process when loading an ELF with PT_TLS segment. Read by sys_exec before enter_usermode to set MSR 0xC0000100.
container_id: AtomicU64Container ID (0 = not containerized). Inherited by forked children so processes cannot escape their container namespace.
clear_child_tid: AtomicU64User-space address to zero and futex-wake on thread exit (set by set_tid_address syscall, used by pthread_join).
robust_list_head: AtomicU64User-space address of robust futex list head (set by set_robust_list syscall for cleanup on abnormal exit).
Implementations§
Source§impl Process
impl Process
Sourcepub fn new(
pid: ProcessId,
parent: Option<ProcessId>,
name: String,
priority: ProcessPriority,
) -> Self
pub fn new( pid: ProcessId, parent: Option<ProcessId>, name: String, priority: ProcessPriority, ) -> Self
Create a new process
Sourcepub fn get_state(&self) -> ProcessState
pub fn get_state(&self) -> ProcessState
Get process state
Sourcepub fn set_state(&self, state: ProcessState)
pub fn set_state(&self, state: ProcessState)
Set process state
Sourcepub fn get_main_thread_id(&self) -> Option<ThreadId>
pub fn get_main_thread_id(&self) -> Option<ThreadId>
Get the main thread ID of this process
Sourcepub fn add_thread(&self, thread: Thread) -> Result<(), KernelError>
pub fn add_thread(&self, thread: Thread) -> Result<(), KernelError>
Add a thread to this process
Sourcepub fn remove_thread(&self, tid: ThreadId) -> Option<Thread>
pub fn remove_thread(&self, tid: ThreadId) -> Option<Thread>
Remove a thread from this process
Sourcepub fn get_thread(&self, tid: ThreadId) -> Option<&Thread>
pub fn get_thread(&self, tid: ThreadId) -> Option<&Thread>
Get a thread by ID
Sourcepub fn thread_count(&self) -> usize
pub fn thread_count(&self) -> usize
Get number of threads
Sourcepub fn add_cpu_time(&self, microseconds: u64)
pub fn add_cpu_time(&self, microseconds: u64)
Update CPU time
Sourcepub fn get_cpu_time(&self) -> u64
pub fn get_cpu_time(&self) -> u64
Get total CPU time
Sourcepub fn set_exit_code(&self, code: i32)
pub fn set_exit_code(&self, code: i32)
Set exit code
Sourcepub fn get_exit_code(&self) -> i32
pub fn get_exit_code(&self) -> i32
Get exit code
Sourcepub fn set_priority(&self, new_priority: ProcessPriority)
pub fn set_priority(&self, new_priority: ProcessPriority)
Set process priority
Sourcepub fn set_clear_child_tid(&self, addr: usize)
pub fn set_clear_child_tid(&self, addr: usize)
Set user-space address to zero and futex-wake on thread exit. Called by set_tid_address syscall; the kernel will write 0 to this address and issue a futex wake when the thread terminates, enabling pthread_join to detect thread completion.
Sourcepub fn set_robust_list(&self, addr: usize)
pub fn set_robust_list(&self, addr: usize)
Set user-space address of the robust futex list head. Called by set_robust_list syscall; the kernel walks this list on abnormal thread exit to unlock any held robust mutexes.
Sourcepub fn memory_space_mut(&mut self) -> Option<&mut VirtualAddressSpace>
pub fn memory_space_mut(&mut self) -> Option<&mut VirtualAddressSpace>
Get mutable reference to memory space
Sourcepub fn get_main_thread_mut(&mut self) -> Option<&mut Thread>
pub fn get_main_thread_mut(&mut self) -> Option<&mut Thread>
Get main thread (first thread created)
Sourcepub fn reset_signal_handlers(&self)
pub fn reset_signal_handlers(&self)
Reset all signal handlers to default (used during exec)
Sourcepub fn set_signal_handler(
&self,
signum: usize,
handler: u64,
) -> Result<u64, KernelError>
pub fn set_signal_handler( &self, signum: usize, handler: u64, ) -> Result<u64, KernelError>
Set a signal handler handler: 0 = default, 1 = ignore, other = handler address
Sourcepub fn get_signal_handler(&self, signum: usize) -> Option<u64>
pub fn get_signal_handler(&self, signum: usize) -> Option<u64>
Get a signal handler
Sourcepub fn send_signal(&self, signum: usize) -> Result<(), KernelError>
pub fn send_signal(&self, signum: usize) -> Result<(), KernelError>
Send a signal to this process
Sourcepub fn is_signal_pending(&self, signum: usize) -> bool
pub fn is_signal_pending(&self, signum: usize) -> bool
Check if a signal is pending
Sourcepub fn get_next_pending_signal(&self) -> Option<usize>
pub fn get_next_pending_signal(&self) -> Option<usize>
Get the next pending signal (lowest numbered, unmasked)
Sourcepub fn clear_pending_signal(&self, signum: usize)
pub fn clear_pending_signal(&self, signum: usize)
Clear a pending signal
Sourcepub fn set_signal_mask(&self, new_mask: u64) -> u64
pub fn set_signal_mask(&self, new_mask: u64) -> u64
Set signal mask (returns old mask)
Sourcepub fn get_signal_mask(&self) -> u64
pub fn get_signal_mask(&self) -> u64
Get current signal mask