|
PatchworkOS
da8a090
A non-POSIX operating system.
|
Processes. More...
Processes.
Processes store the shared resources for threads of execution, for example the address space and open files.
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.
Included below is a list of all entries found in the /proc/[pid] directory along with their formats.
A readable and writable file that contains the scheduling priority of the process.
Format:
A readable and writable file that contains the current working directory of the process.
Format:
A readable file that contains the command line arguments of the process (argv).
Format:
A writable file that can be used to send notes to the process. Writing data to this file will enqueue that data as a note in the note queue of one of the process's threads.
A readable and pollable file that can be used to wait for the process to exit and retrieve its exit status. Reading from this file will block until the process has exited.
Format:
A readable file that contains performance statistics for the process.
Format:
A writable file that can be used to control certain aspects of the process, such as closing file descriptors.
Included is a list of all supported commands.
Closes the specified file descriptor in the process.
Closes the range [minfd, maxfd) of file descriptors in the process.
Note that specifying -1 as maxfd will close all file descriptors from minfd to the maximum allowed file descriptor.
Duplicates the specified old file descriptor to the new file descriptor in the process.
Starts the process if it was previously suspended.
Sends a kill note to all threads in the process, effectively terminating it.
/proc/[pid]/fd directory.A directory that contains the environment variables of the process. Each environment variable is represented as a readable and writable file whose name is the name of the variable and whose content is the value of the variable.
To add or modify an environment variable, create or write to a file with the name of the variable. To remove an environment variable, delete the corresponding file.
Data Structures | |
| struct | process_threads_t |
| Represents the threads in a process. More... | |
| struct | process_t |
| Process structure. More... | |
Enumerations | |
| enum | process_flags_t { PROCESS_NONE = 0 , PROCESS_DYING = 1 << 0 , PROCESS_SUSPENDED = 1 << 1 } |
| Process flags enum. More... | |
Functions | |
| process_t * | process_new (priority_t priority) |
| Allocates and initializes a new process. | |
| void | process_kill (process_t *process, int32_t status) |
| Kills a process. | |
| uint64_t | process_copy_env (process_t *dest, process_t *src) |
| Copies the environment variables from one process to another. | |
| 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_t * | process_get_kernel (void) |
| Gets the kernel process. | |
| void | process_procfs_init (void) |
Initializes the /proc directory. | |
| void | process_reaper_init (void) |
| Initializes the process reaper. | |
| enum process_flags_t |
| process_t * process_new | ( | priority_t | priority | ) |
Allocates and initializes a new process.
There is no process_free(), instead use UNREF(), UNREF_DEFER() or process_kill() to free a process.
| priority | The priority of the new process. |
NULL and errno is set. Definition at line 718 of file process.c.
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.
| process | The process to kill. |
| status | The exit status of the process. |
Definition at line 776 of file process.c.
Copies the environment variables from one process to another.
| dest | The destination process, must have an empty environment. |
| src | The source process. |
0. On failure, ERR and errno is set to:EINVAL: Invalid parameters.EBUSY: The destination process already has environment variables. Definition at line 817 of file process.c.
Sets the command line arguments for a process.
This value is only used for the /proc/[pid]/cmdline file.
| process | The process to set the cmdline for. |
| argv | The array of argument strings. |
| argc | The number of arguments. |
0. On failure, ERR and errno is set to:EINVAL: Invalid parameters.ENOMEM: Out of memory. Definition at line 869 of file process.c.
| 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.
Definition at line 943 of file process.c.
| void process_procfs_init | ( | void | ) |
| void process_reaper_init | ( | void | ) |
Initializes the process reaper.
The process reaper allows us to delay the freeing of processes, this is useful if, for example, another process wanted that process's exit status.
Definition at line 1032 of file process.c.