~emersion/mrsh

ref: 537899b8a63adf88d442790b4cf6a38edd9288d9 mrsh/include/shell/process.h -rw-r--r-- 1.0 KiB
537899b8Simon Ser shell/arithm: strip mrsh_ prefix for static functions 2 years ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#ifndef SHELL_PROCESS_H
#define SHELL_PROCESS_H

#include <mrsh/shell.h>
#include <stdbool.h>
#include <sys/types.h>

/**
 * This struct is used to track child processes.
 *
 * This object is guaranteed to be valid until either:
 * - The process terminates
 * - The shell is destroyed
 */
struct process {
	pid_t pid;
	struct mrsh_state *state;
	bool stopped;
	bool terminated;
	int stat; // only valid if terminated
	int signal; // only valid if stopped is true
};

/**
 * Register a new process.
 */
struct process *process_create(struct mrsh_state *state, pid_t pid);
void process_destroy(struct process *process);
/**
 * Polls the process' current status without blocking. Returns:
 * - An integer >= 0 if the process has terminated
 * - TASK_STATUS_STOPPED if the process is stopped
 * - TASK_STATUS_WAIT if the process is running
 */
int process_poll(struct process *process);

/**
 * Update the shell's state with a child process status.
 */
void update_process(struct mrsh_state *state, pid_t pid, int stat);

#endif