1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-06-01 08:28:11 +00:00

HackStudio: Add TerminalWrapper::kill_running_command()

Also put our child process into a new process group in order to be
able to kill it along with its own children.
This commit is contained in:
Sergey Bugaev 2019-11-14 19:21:13 +03:00 committed by Andreas Kling
parent cd11a8597a
commit 8484635920
2 changed files with 14 additions and 0 deletions

View file

@ -6,9 +6,11 @@
#include <LibGUI/GMessageBox.h>
#include <LibVT/TerminalWidget.h>
#include <fcntl.h>
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/ioctl.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <unistd.h>
@ -54,6 +56,9 @@ void TerminalWrapper::run_command(const String& command)
m_pid = fork();
if (m_pid == 0) {
// Create a new process group.
setsid();
const char* tty_name = ptsname(ptm_fd);
if (!tty_name) {
perror("ptsname");
@ -116,6 +121,14 @@ void TerminalWrapper::run_command(const String& command)
m_process_state_widget->set_tty_fd(ptm_fd);
}
void TerminalWrapper::kill_running_command()
{
ASSERT(m_pid != -1);
// Kill our child process and its whole process group.
(void)killpg(m_pid, SIGTERM);
}
TerminalWrapper::TerminalWrapper(GWidget* parent)
: GWidget(parent)
{

View file

@ -11,6 +11,7 @@ public:
virtual ~TerminalWrapper() override;
void run_command(const String&);
void kill_running_command();
Function<void()> on_command_exit;