85 lines
5.3 KiB
Markdown
85 lines
5.3 KiB
Markdown
|
# process.h
|
||
|
|
||
|
Processes are the containers, in which threads are organized.
|
||
|
|
||
|
# `MAX_THREADS_PER_PROCESS` - macro
|
||
|
The maximum amount of threads a process can have.
|
||
|
This limitation is just for the bitmap,
|
||
|
the overall processing structure would be capable of processes with unlimited threads, in theory.
|
||
|
|
||
|
# `THREAD_ID_INVALID` - macro
|
||
|
If process_get_thread_id() returns this, the process can't spawn one more thread.
|
||
|
|
||
|
# `pid_t` - typedef
|
||
|
A typedef for `uint32_t`, used for process identification.
|
||
|
Such an identification number is also called `pid`.
|
||
|
|
||
|
# `processes_standard_E` - enum
|
||
|
These are standard pids
|
||
|
- **None** - This pid is invalid, like `NULL` is an invalid pointer
|
||
|
- **Kernel** - The kernels' main process
|
||
|
|
||
|
# `process_blockers_E` - enum
|
||
|
- **PIPE_OUT** - This blocker becomes activated, when the process tries to write to a pipe, but the pipe has not enough space for the data. It becomes deactivated, when the pipe has space to fit the rest of the data.
|
||
|
- **PIPE_IN** - This blocker becomes activated, when the process tries to read from a pipe, but the pipe has not the requested amount of data. It becomes deactivated, when the pipe contains data again.
|
||
|
|
||
|
# `process_T` - struct
|
||
|
|
||
|
| Name | Type | Description |
|
||
|
|-------------|----------------------------|-----------------------------------------------------------------------------------------|
|
||
|
| name | char[128] | The processes' name |
|
||
|
| id | pid_t | The process-identification number |
|
||
|
| chunk | void* | A pointer to the chunk, where the process is stored in |
|
||
|
| chunk_id | uint32_t | The processes id inside of its chunk |
|
||
|
| page_map | page_map_T* | The processes page map. |
|
||
|
| executable | elf_executable_T* | The processes executable |
|
||
|
| fd_array | file_descriptor_array_T* | Contains the open file descriptors of the process. |
|
||
|
| stdout | pipe_T* | Pointer to the pipe, where **stdout** writes to. |
|
||
|
| stdin | pipe_T | The pipe, where **stdin** reads from. |
|
||
|
| stderr | pipe_T* | Pointer to the pipe, where **stderr** writes to. |
|
||
|
| waiting | bitmap_T | A bitmap of process blockers. If this is greater 0 the process is blocked by something. |
|
||
|
| num_threads | uint32_t | The amount of spawned threads, that belong to the process |
|
||
|
| threads | void* | A pointer to the processes' first thread |
|
||
|
| thread_ids | bitmap_T(reference needed) | This bitmap keeps track of the local thread ids the process has |
|
||
|
| parent | process_T* | The process, that spawned this process |
|
||
|
| childs | process_T* | A pointer to the processes' first child process |
|
||
|
| prev | process_T* | The previous process |
|
||
|
| next | process_T* | The next process |
|
||
|
|
||
|
|
||
|
# `process_kernel_spawn(executable)` - function (void)
|
||
|
Spawns the kernels' main process.
|
||
|
|
||
|
**Warning:** this should only be called once, when initializing the scheduler!
|
||
|
|
||
|
# `process_spawn(parent, name, executable, buffer)` - function (pid_t)
|
||
|
Spawns a process named **_name_** as child of **_parent_** and returns its pid.
|
||
|
The process gets its own page map with the mappings specified in **_executable_**.
|
||
|
In order to apply these mappings, this function needs the **_buffer_** where the executable was loaded from.
|
||
|
|
||
|
# `process_get_thread_id(process)` - function (int32_t)
|
||
|
Searches for a free thread id in the process.
|
||
|
If it finds one it returns it, else it returns THREAD_ID_INVALID.
|
||
|
|
||
|
# `process_clear_thread_id(process, id)` - function (void)
|
||
|
Frees the thread **_id_** and makes it request-able again.
|
||
|
|
||
|
# `process_pause_pid(pid)` - function (void)
|
||
|
Resolves the pids process and performs `process_pause` on it.
|
||
|
|
||
|
# `process_pause(process)` - function (void)
|
||
|
Pauses **_process_** and all of its threads.
|
||
|
|
||
|
# `process_start_pid(pid)` - function (void)
|
||
|
Resolves the pids process and performs `process_start` on it.
|
||
|
|
||
|
# `process_start(process)` - function (void)
|
||
|
Starts **_process_** and all of its threads.
|
||
|
|
||
|
# `process_kill_pid(pid)` - function (void)
|
||
|
Resolves the pids process and performs `process_kill` on it.
|
||
|
|
||
|
# `process_kill(process)` - function (void)
|
||
|
Kills **_process_** and all of its threads and child processes.
|
||
|
This will also destruct the `executable` and `page_map` associated with **_process_**.
|