diff --git a/src/process.cpp b/src/process.cpp index 2342d30..6cdcf54 100644 --- a/src/process.cpp +++ b/src/process.cpp @@ -350,19 +350,16 @@ bool IsValid(Process *process) { return false; } - int status = 0; - pollfd p = {}; - p.fd = plat->child_stdout_read; - p.events = POLLRDHUP | POLLERR | POLLHUP | POLLNVAL; - int res = poll(&p, 1, 0); - if (res > 0) { - pid_t result = waitpid(plat->pid, &status, 0); - Assert(result != -1); - process->exit_code = WEXITSTATUS(status); - return false; + int status = 0; + pid_t result = waitpid(plat->pid, &status, WNOHANG); + if (result == 0) { + return true; } - return true; + Assert(result != -1); + process->exit_code = WIFEXITED(status) ? WEXITSTATUS(status) : -1; + process->is_valid = false; + return false; } void KillProcess(Process *process) { @@ -384,7 +381,7 @@ String PollStdout(Allocator allocator, Process *process, bool force_read) { p.events = POLLIN; int res = poll(&p, 1, 0); if (res > 0 || force_read) { - result.len = read(plat->child_stdout_read, result.data, 4 * 4096); + result.len = read(plat->child_stdout_read, result.data, 16 * 4096); } return result; } @@ -471,10 +468,9 @@ void UpdateProcesses() { View *view = GetView(it.args.output_view); String poll = PollStdout(scratch, &it, false); - if (poll.len) { + if (poll.len > 0) { Append(view, poll, it.args.scroll_to_end); - } - if (!IsValid(&it)) { + } else if (!IsValid(&it)) { ReportConsolef("process %lld exit code = %d", it.id, it.exit_code); remove_item = true; }