mirror of
https://github.com/JannisHeydemann/BoredOS.git
synced 2026-05-30 10:26:59 +00:00
pr: Fix process slot exhaustion in process lifecycle (#16)
* fix process slot reuse after exit * fix terminal tty reuse after close
This commit is contained in:
@@ -897,24 +897,10 @@ static void show_matches(const char *prompt_tmpl, const char *line, int len, cha
|
||||
redraw_input(prompt_tmpl, line, len, len);
|
||||
}
|
||||
|
||||
static int pid_exists(int pid) {
|
||||
char path[64];
|
||||
path[0] = 0;
|
||||
strcat(path, "/proc/");
|
||||
char pid_buf[16];
|
||||
itoa(pid, pid_buf);
|
||||
strcat(path, pid_buf);
|
||||
strcat(path, "/status");
|
||||
int fd = sys_open(path, "r");
|
||||
if (fd < 0) return 0;
|
||||
char buf[8];
|
||||
int bytes = sys_read(fd, buf, sizeof(buf));
|
||||
sys_close(fd);
|
||||
return bytes > 0;
|
||||
}
|
||||
|
||||
static void wait_for_pid(int pid) {
|
||||
while (pid_exists(pid)) {
|
||||
while (1) {
|
||||
int rc = sys_waitpid(pid, NULL, 1);
|
||||
if (rc == pid || rc < 0) break;
|
||||
if (g_tty_id >= 0) {
|
||||
int fg = sys_tty_get_fg(g_tty_id);
|
||||
if (fg != pid) break;
|
||||
|
||||
@@ -1224,7 +1224,8 @@ int main(void) {
|
||||
while (ui_get_event(g_win, &ev)) {
|
||||
if (ev.type == GUI_EVENT_CLOSE) {
|
||||
for (int i = 0; i < g_tab_count; i++) {
|
||||
if (g_tabs[i].bsh_pid > 0) sys_kill(g_tabs[i].bsh_pid);
|
||||
sys_tty_kill_all(g_tabs[i].tty_id);
|
||||
sys_tty_destroy(g_tabs[i].tty_id);
|
||||
}
|
||||
sys_exit(0);
|
||||
} else if (ev.type == GUI_EVENT_KEY) {
|
||||
|
||||
Reference in New Issue
Block a user