PatchworkOS
Loading...
Searching...
No Matches
Processes

Processes. More...

Modules

 Argument Vector
 Argument Vector.
 

Data Structures

struct  process_threads_t
 Process threads structure. More...
 
struct  process_t
 Process structure. More...
 

Functions

process_tprocess_new (process_t *parent, const char **argv, const path_t *cwd, priority_t priority)
 Allocates and initializes a new process.
 
void process_kill (process_t *process, uint64_t status)
 Kills a process.
 
bool process_is_child (process_t *process, pid_t parentId)
 Checks if a process is a child of another process.
 
process_tprocess_get_kernel (void)
 Gets the kernel process.
 
void process_procfs_init (void)
 Initializes the /proc directory.
 

Detailed Description

Processes.

Processes store the shared resources for threads of execution, for example the address space and open files.

Process Filesystem

Each process has a directory located at /proc/[pid], which contains various files that can be used to interact with the process. Additionally, there is a /proc/self bound mount point that points to the /proc/[pid] directory of the current process. These files include:

Function Documentation

◆ process_get_kernel()

process_t * process_get_kernel ( void  )

Gets the kernel process.

The kernel process will be initalized lazily on the first call to this function, which should happen during early boot.

Will never return NULL.

Will not increment the reference count of the returned process as it should never be freed either way.

Returns
The kernel process.

Definition at line 594 of file process.c.

References ERR, process_t::id, kernelProcess, kernelProcessInitalized, LOG_INFO, NULL, panic(), PRIORITY_MAX, and process_init().

Referenced by namespace_bind(), namespace_get_root_path(), namespace_mount(), sched_cpu_ctx_init(), sched_done_with_boot_thread(), sysfs_mount_new(), thread_get_boot(), and vfs_ctx_get_cwd().

◆ process_is_child()

bool process_is_child ( process_t process,
pid_t  parentId 
)

Checks if a process is a child of another process.

Parameters
processThe process to check.
parentIdThe parent process id.
Returns
true if the process is a child of the parent with id parentId, false otherwise.

Definition at line 529 of file process.c.

References DEREF, NULL, process_t::parent, REF, and RWLOCK_READ_SCOPE.

Referenced by process_init().

◆ process_kill()

void process_kill ( process_t process,
uint64_t  status 
)

Kills a process.

Sends a kill note to all threads in the process and sets its exit status. Will also close all files opened by the process and deinitialize its /proc directory.

When all threads have exited and all entires in its /proc directory have been closed, the process will be freed.

Parameters
processThe process to kill.
statusThe exit status of the process.

Definition at line 483 of file process.c.

References atomic_exchange, atomic_store, ref_t::count, process_t::dyingWaitQueue, EOK, process_t::id, process_t::isDying, process_threads_t::list, LIST_FOR_EACH, list_push(), process_threads_t::lock, LOCK_SCOPE, LOG_DEBUG, namespace_deinit(), process_t::ref, REF, thread_send_note(), process_t::threads, timer_uptime(), vfs_ctx_deinit(), process_t::vfsCtx, WAIT_ALL, and wait_unblock().

Referenced by exception_handler(), note_interrupt_handler(), process_free(), and sched_process_exit().

◆ process_new()

process_t * process_new ( process_t parent,
const char **  argv,
const path_t cwd,
priority_t  priority 
)

Allocates and initializes a new process.

There is no process_free(), instead use DEREF(), DEREF_DEFER() or process_kill() to free a process.

Parameters
parentThe parent process, can be NULL.
argvThe argument vector, must be NULL terminated.
cwdThe current working directory, can be NULL to inherit from the parent.
priorityThe priority of the new process.
Returns
On success, the newly created process. On failure, NULL and errno is set.

Definition at line 458 of file process.c.

References DEREF, ERR, free(), process_t::id, malloc(), MAX_NAME, NULL, process_dir_init(), process_init(), and snprintf().

Referenced by loader_spawn().

◆ process_procfs_init()

void process_procfs_init ( void  )