|
PatchworkOS
|
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_t * | process_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_t * | process_get_kernel (void) |
| Gets the kernel process. | |
| void | process_procfs_init (void) |
Initializes the /proc directory. | |
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. These files include:
prio: A readable and writable file that contains the scheduling priority of the process.cwd: A readable file that contains the current working directory of the process.cmdline: A readable file that contains the command line arguments of the process (argv).note: A writable file that can be used to send notes (see note_queue_t) to the process.wait: A readable and pollable file that can be used to wait for the process to exit and retrieve its exit status. | 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 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().
Checks if a process is a child of another process.
| process | The process to check. |
| parentId | The parent process id. |
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().
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 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_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.
| parent | The parent process, can be NULL. |
| argv | The argument vector, must be NULL terminated. |
| cwd | The current working directory, can be NULL to inherit from the parent. |
| priority | The priority of the new process. |
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().
| void process_procfs_init | ( | void | ) |
Initializes the /proc directory.
Definition at line 567 of file process.c.
References assert, ERR, process_t::id, kernelProcess, kernelProcessInitalized, MAX_NAME, NULL, panic(), process_dir_init(), mount_t::root, smp_self_unsafe(), snprintf(), sysfs_dir_new(), sysfs_mount_new(), and timer_subscribe().
Referenced by init_finalize().