-
Notifications
You must be signed in to change notification settings - Fork 0
/
tasks.h
151 lines (130 loc) · 2.87 KB
/
tasks.h
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
//
// tasks.h
// yxsh
//
// Created by Kirill on 19.04.2018.
// Copyright © 2018 Kirill. All rights reserved.
//
#ifndef _TASKS_H
#define _TASKS_H
#include <sys/types.h>
#include <stdbool.h>
#include "shell.h"
#define MAXTSKS 1024
typedef struct task {
pid_t pgid;
int status;
size_t id;
size_t count;
char* display_name;
size_t pids_amount;
pid_t* pids;
} task_t;
typedef struct tasks_env {
task_t* tasks[MAXTSKS];
size_t tasks_size;
} tasks_env_t;
/**
* Creates new tasks environment.
*
* @param env Result of creation.
*/
void tasks_create_env(tasks_env_t* env);
/**
* Runs the task and monitors its status until it finishes.
*
* @param env Current environment.
* @param pgid Process group ID of task.
* @param bg Is this task background.
* @param display Task display name.
*
* @return true if task created.
*/
bool tasks_run_task(tasks_env_t* env, pid_t pgid, bool bg, char* display);
/**
* Runs the pipeline task and monitors its status until it finishes.
*
* @param env Current environment.
* @param pgid Process group ID of pipeline group.
* @param pids Process IDs for all line.
* @param bg Is this task background.
* @param num Number of commands in pipeline.
* @param display Task display name.
*
* @return true if task created.
*/
bool tasks_run_pipeline(tasks_env_t* env, pid_t pgid, pid_t* pids,
bool bg, size_t num, char* display);
/**
* Checks for avaliable task id to create new task.
*
* @param env Current environment.
*
* @return true if it has free id.
*/
bool tasks_has_free(tasks_env_t* env);
/**
* Finishes all background tasks and free memory.
*
* @param env Current envitonment.
*/
void tasks_release_env(tasks_env_t* env);
/**
* Collects all finished (zombies) processes.
*
* @param env Current environment.
*/
void tasks_collect_zombies(tasks_env_t* env);
/**
* Updates process status in background tasks list.
*
* @param env Current environment.
*
* @return Is some status updates dumped.
*/
bool tasks_update_status(tasks_env_t* env);
/**
* Prints tasks list with ids.
*
* @param env Current environment.
*/
void tasks_dump_list(tasks_env_t* env);
/**
* Searches task by specified id.
*
* @param env Current environment.
* @param id Task id.
*
* @return Task by id or NULL, if not found.
*/
task_t* task_by_id(tasks_env_t* env, size_t id);
/**
* Resumes suspended task into background.
*
* @param task Task.
*/
void task_resume_background(task_t* task);
/**
* Resumes suspended task into foreground.
*
* @param env Current environment.
* @param task Task.
*/
void task_resume_foreground(tasks_env_t* env, task_t* task);
/**
* Waits for task.
*
* @param task Task.
*
* @return true if task finished.
*/
bool task_wait(task_t* task);
/**
* Setting up pid to stdin.
*
* @param pid Process id to setup.
*
* @return true if success.
*/
bool setup_terminal(pid_t pid);
#endif /* _TASKS_H */