PatchworkOS  966e257
A non-POSIX operating system.
Loading...
Searching...
No Matches
group.h
Go to the documentation of this file.
1#pragma once
2
3#include <kernel/sync/lock.h>
4#include <kernel/utils/map.h>
5
6#include <sys/list.h>
7#include <sys/proc.h>
8
9typedef struct process process_t;
10
11typedef struct group group_t;
12
13/**
14 * @brief Process groups.
15 * @defgroup kernel_proc_group Process groups
16 * @ingroup kernel_proc
17 *
18 * Process groups allow related processes to be grouped together, enabling operations such as sending
19 * notes to all processes within a group.
20 *
21 * As an example, if a user wishes to terminate a shell they most likely additionally want to terminate all
22 * child processes started by that shell. By placing all such processes in the same group, a single "terminate" note
23 * can be sent to the entire group, effectively terminating all related processes.
24 *
25 * @{
26 */
27
28/**
29 * @brief Group entry structure.
30 * @struct group_entry_t
31 *
32 * Stored in `process_t::groupEntry`.
33 */
39
40/**
41 * @brief Process group structure.
42 * @struct group_t
43 */
44typedef struct group
45{
49} group_t;
50
51/**
52 * @brief Initializes a group entry.
53 *
54 * @param entry The group entry to initialize.
55 */
57
58/**
59 * @brief Deinitializes a group entry.
60 *
61 * @param entry The group entry to deinitialize.
62 */
64
65/**
66 * @brief Adds a process to a group.
67 *
68 * @param gid The group ID to add the process to, or `GID_NONE` to create a new group.
69 * @param entry The group entry of the process to add to the group.
70 * @return On success, `0`. On failure, `ERR` and errno is set to:
71 * - `EINVAL`: Invalid parameters.
72 * - `ENOENT`: The specified group does not exist.
73 * - `EBUSY`: The entry is already part of a group.
74 * - `ENOMEM`: Out of memory.
75 */
77
78/**
79 * @brief Removes a process from its group.
80 *
81 * If the group becomes empty after removing the process, it will be freed.
82 *
83 * @param entry The group entry of the process to remove from its group, or `NULL` for no-op.
84 */
85void group_remove(group_entry_t* entry);
86
87/**
88 * @brief Gets the ID of the group of the specified entry.
89 *
90 * @param entry The group entry to get the group ID from.
91 * @return The group ID or `GID_NONE` if the entry is not part of a group.
92 */
94
95/**
96 * @brief Sends a note to all processes in the group of the specified entry.
97 *
98 * @param entry The entry within the group to send the note to.
99 * @param note The note string to send.
100 * @return On success, `0`. On failure, `ERR` and `errno` is set to:
101 * - `EINVAL`: Invalid parameters.
102 * - Other values from `thread_send_note()`.
103 */
104uint64_t group_send_note(group_entry_t* entry, const char* note);
105
106/** @} */
uint64_t group_send_note(group_entry_t *entry, const char *note)
Sends a note to all processes in the group of the specified entry.
Definition group.c:115
void group_entry_init(group_entry_t *entry)
Initializes a group entry.
Definition group.c:14
void group_entry_deinit(group_entry_t *entry)
Deinitializes a group entry.
Definition group.c:20
void group_remove(group_entry_t *entry)
Removes a process from its group.
Definition group.c:73
uint64_t group_add(gid_t gid, group_entry_t *entry)
Adds a process to a group.
Definition group.c:25
gid_t group_get_id(group_entry_t *entry)
Gets the ID of the group of the specified entry.
Definition group.c:98
__UINT64_TYPE__ gid_t
Group Identifier.
Definition gid_t.h:11
__UINT64_TYPE__ uint64_t
Definition stdint.h:17
Group entry structure.
Definition group.h:35
group_t * group
Definition group.h:37
list_entry_t entry
Definition group.h:36
Process group structure.
Definition group.h:45
map_entry_t mapEntry
Definition group.h:46
list_t processes
Definition group.h:48
gid_t id
Definition group.h:47
A entry in a doubly linked list.
Definition list.h:36
A doubly linked list.
Definition list.h:49
Map entry structure.
Definition map.h:68
Process structure.
Definition process.h:205