PatchworkOS
966e257
A non-POSIX operating system.
Theme:
Default
Round
Robot
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
9
typedef
struct
process
process_t
;
10
11
typedef
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
*/
34
typedef
struct
35
{
36
list_entry_t
entry
;
37
group_t
*
group
;
38
}
group_entry_t
;
39
40
/**
41
* @brief Process group structure.
42
* @struct group_t
43
*/
44
typedef
struct
group
45
{
46
map_entry_t
mapEntry
;
47
gid_t
id
;
48
list_t
processes
;
49
}
group_t
;
50
51
/**
52
* @brief Initializes a group entry.
53
*
54
* @param entry The group entry to initialize.
55
*/
56
void
group_entry_init
(
group_entry_t
* entry);
57
58
/**
59
* @brief Deinitializes a group entry.
60
*
61
* @param entry The group entry to deinitialize.
62
*/
63
void
group_entry_deinit
(
group_entry_t
* entry);
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
*/
76
uint64_t
group_add
(
gid_t
gid,
group_entry_t
* entry);
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
*/
85
void
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
*/
93
gid_t
group_get_id
(
group_entry_t
* entry);
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
*/
104
uint64_t
group_send_note
(
group_entry_t
* entry,
const
char
* note);
105
106
/** @} */
group_send_note
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
group_entry_init
void group_entry_init(group_entry_t *entry)
Initializes a group entry.
Definition
group.c:14
group_entry_deinit
void group_entry_deinit(group_entry_t *entry)
Deinitializes a group entry.
Definition
group.c:20
group_remove
void group_remove(group_entry_t *entry)
Removes a process from its group.
Definition
group.c:73
group_add
uint64_t group_add(gid_t gid, group_entry_t *entry)
Adds a process to a group.
Definition
group.c:25
group_get_id
gid_t group_get_id(group_entry_t *entry)
Gets the ID of the group of the specified entry.
Definition
group.c:98
gid_t
__UINT64_TYPE__ gid_t
Group Identifier.
Definition
gid_t.h:11
list.h
lock.h
map.h
proc.h
uint64_t
__UINT64_TYPE__ uint64_t
Definition
stdint.h:17
group_entry_t
Group entry structure.
Definition
group.h:35
group_entry_t::group
group_t * group
Definition
group.h:37
group_entry_t::entry
list_entry_t entry
Definition
group.h:36
group_t
Process group structure.
Definition
group.h:45
group_t::mapEntry
map_entry_t mapEntry
Definition
group.h:46
group_t::processes
list_t processes
Definition
group.h:48
group_t::id
gid_t id
Definition
group.h:47
list_entry_t
A entry in a doubly linked list.
Definition
list.h:36
list_t
A doubly linked list.
Definition
list.h:49
map_entry_t
Map entry structure.
Definition
map.h:68
process_t
Process structure.
Definition
process.h:205
include
kernel
proc
group.h
Generated on Mon Dec 15 2025 21:55:53 for PatchworkOS by
1.9.8