PatchworkOS  19e446b
A non-POSIX operating system.
Loading...
Searching...
No Matches
Process Subsystem

Process management. More...

Collaboration diagram for Process Subsystem:

Detailed Description

Process management.

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

Modules

 Environment
 Environment variables.
 
 Process groups
 Process groups.
 
 Process reaper
 Process reaper for delayed process freeing.
 

Data Structures

struct  process_threads_t
 Represents the threads in a process. More...
 
struct  process_status_t
 Process exit status structure. More...
 
struct  process_t
 Process structure. More...
 

Macros

#define PROCESS_STATUS_MAX   256
 Maximum length of a process exit status.
 
#define PROCESS_RCU_THREAD_FOR_EACH(thread, process)   LIST_FOR_EACH(thread, &(process)->threads.list, processEntry)
 Macro to iterate over all threads in a process.
 
#define PROCESS_RCU_FOR_EACH(process)   LIST_FOR_EACH(process, &_processes, entry)
 Macro to iterate over all processes.
 

Enumerations

enum  process_flags_t { PROCESS_NONE = 0 , PROCESS_DYING = 1 << 0 , PROCESS_SUSPENDED = 1 << 1 }
 Process flags enum. More...
 

Functions

process_tprocess_new (priority_t priority, group_member_t *group, namespace_t *ns)
 Allocates and initializes a new process.
 
static process_tprocess_current (void)
 Retrieves the process of the currently running thread.
 
static process_tprocess_current_unsafe (void)
 Retrieves the process of the currently running thread without disabling interrupts.
 
process_tprocess_get (pid_t id)
 Gets a process by its ID.
 
namespace_tprocess_get_ns (process_t *process)
 Gets the namespace of a process.
 
void process_set_ns (process_t *process, namespace_t *ns)
 Sets the namespace of a process.
 
void process_kill (process_t *process, const char *status)
 Kills a process, pushing it to the reaper.
 
void process_remove (process_t *process)
 Removes a process from the system.
 
static thread_tprocess_rcu_first_thread (process_t *process)
 Gets the first thread of a process.
 
static uint64_t process_rcu_thread_count (process_t *process)
 Gets the amount of threads in a process.
 
uint64_t process_set_cmdline (process_t *process, char **argv, uint64_t argc)
 Sets the command line arguments for a process.
 
bool process_has_thread (process_t *process, tid_t tid)
 Checks if a process has a thread with the specified thread ID.
 
process_tprocess_get_kernel (void)
 Gets the kernel process.
 

Variables

list_t _processes
 Global list of all processes.
 

Macro Definition Documentation

◆ PROCESS_STATUS_MAX

#define PROCESS_STATUS_MAX   256

Maximum length of a process exit status.

Definition at line 59 of file process.h.

◆ PROCESS_RCU_THREAD_FOR_EACH

#define PROCESS_RCU_THREAD_FOR_EACH (   thread,
  process 
)    LIST_FOR_EACH(thread, &(process)->threads.list, processEntry)

Macro to iterate over all threads in a process.

Warning
Must be used within a RCU read-side critical section.
Parameters
threadLoop variable, a pointer to thread_t.
processThe process to iterate the threads of.

Definition at line 232 of file process.h.

◆ PROCESS_RCU_FOR_EACH

#define PROCESS_RCU_FOR_EACH (   process)    LIST_FOR_EACH(process, &_processes, entry)

Macro to iterate over all processes.

Warning
Must be used within a RCU read-side critical section.
Parameters
processLoop variable, a pointer to process_t.

Definition at line 241 of file process.h.

Enumeration Type Documentation

◆ process_flags_t

Process flags enum.

Enumerator
PROCESS_NONE 
PROCESS_DYING 
PROCESS_SUSPENDED 

Definition at line 37 of file process.h.

Function Documentation

◆ process_new()

process_t * process_new ( priority_t  priority,
group_member_t group,
namespace_t ns 
)

Allocates and initializes a new process.

It is the responsibility of the caller to UNREF() the returned process.

Parameters
priorityThe priority of the new process.
groupA member of the group to add the new process to, or NULL to create a new group for the process.
nsThe namespace to use for the new process.
Returns
On success, the newly created process. On failure, NULL and errno is set.

Definition at line 125 of file process.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ process_current()

static process_t * process_current ( void  )
inlinestatic

Retrieves the process of the currently running thread.

Note
Will not increment the reference count of the returned process, as we consider the currently running thread to always be referencing its process.
Returns
The process of the currently running thread.

Definition at line 131 of file process.h.

Here is the caller graph for this function:

◆ process_current_unsafe()

static process_t * process_current_unsafe ( void  )
inlinestatic

Retrieves the process of the currently running thread without disabling interrupts.

Note
Will not increment the reference count of the returned process, as we consider the currently running thread to always be referencing its process.
Returns
The process of the currently running thread.

Definition at line 145 of file process.h.

Here is the caller graph for this function:

◆ process_get()

process_t * process_get ( pid_t  id)

Gets a process by its ID.

It is the responsibility of the caller to UNREF() the returned process.

Parameters
idThe ID of the process to get.
Returns
A reference to the process with the specified ID or NULL if no such process exists.

Definition at line 192 of file process.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ process_get_ns()

namespace_t * process_get_ns ( process_t process)

Gets the namespace of a process.

It is the responsibility of the caller to UNREF() the returned namespace.

Parameters
processThe process to get the namespace of.
Returns
On success, a reference to the namespace of the process. On failure, NULL and errno is set:
  • EINVAL: Invalid parameters.

Definition at line 206 of file process.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ process_set_ns()

void process_set_ns ( process_t process,
namespace_t ns 
)

Sets the namespace of a process.

Parameters
processThe process to set the namespace of.
nsThe new namespace for the process.

Definition at line 227 of file process.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ process_kill()

void process_kill ( process_t process,
const char *  status 
)

Kills a process, pushing it to the reaper.

The process will still exist until the reaper removes it.

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

Definition at line 240 of file process.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ process_remove()

void process_remove ( process_t process)

Removes a process from the system.

This should only be called by the reaper.

Parameters
processThe process to remove.

Definition at line 284 of file process.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ process_rcu_first_thread()

static thread_t * process_rcu_first_thread ( process_t process)
inlinestatic

Gets the first thread of a process.

Warning
Must be used within a RCU read-side critical section.
Parameters
processThe process to get the first thread of.
Returns
The first thread of the process, or NULL if the process has no threads.

Definition at line 206 of file process.h.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ process_rcu_thread_count()

static uint64_t process_rcu_thread_count ( process_t process)
inlinestatic

Gets the amount of threads in a process.

Warning
Must be used within a RCU read-side critical section.
Parameters
processThe process to get the thread amount of.
Returns
The amount of threads in the process.

Definition at line 219 of file process.h.

Here is the caller graph for this function:

◆ process_set_cmdline()

uint64_t process_set_cmdline ( process_t process,
char **  argv,
uint64_t  argc 
)

Sets the command line arguments for a process.

This value is only used for the /proc/[pid]/cmdline file.

Parameters
processThe process to set the cmdline for.
argvThe array of argument strings.
argcThe number of arguments.
Returns
On success, 0. On failure, ERR and errno is set to:
  • EINVAL: Invalid parameters.
  • ENOMEM: Out of memory.

Definition at line 294 of file process.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ process_has_thread()

bool process_has_thread ( process_t process,
tid_t  tid 
)

Checks if a process has a thread with the specified thread ID.

Parameters
processThe process to check.
tidThe thread ID to look for.
Returns
true if the process has a thread with the specified ID, false otherwise.

Definition at line 358 of file process.c.

Here is the caller graph for this function:

◆ 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 and will not increment the reference count of the returned process.

Returns
The kernel process.

Definition at line 374 of file process.c.

Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

◆ _processes

list_t _processes
extern

Global list of all processes.

Warning
Should only be read while in a RCU read-side critical section.