LibCore: Port Process to Windows

Windows doesn't have a concept of zombie children, hence:
* `disown` not needed
* we need a process handle because otherwise if the process have ended
  by the time `wait_for_termination` is called
  its pid may be reassigned to other process
This commit is contained in:
stasoid 2024-11-17 22:07:43 +05:00 committed by Andrew Kaster
commit 3468a83e45
Notes: github-actions[bot] 2024-11-19 22:28:29 +00:00
3 changed files with 200 additions and 18 deletions

View file

@ -61,6 +61,24 @@ struct ArgvList {
}
};
Process::Process(Process&& other)
: m_pid(exchange(other.m_pid, 0))
, m_should_disown(exchange(other.m_should_disown, false))
{
}
Process& Process::operator=(Process&& other)
{
m_pid = exchange(other.m_pid, 0);
m_should_disown = exchange(other.m_should_disown, false);
return *this;
}
Process::~Process()
{
(void)disown();
}
Process Process::current()
{
auto p = Process { getpid() };
@ -297,6 +315,11 @@ void Process::wait_for_debugger_and_break()
}
}
pid_t Process::pid() const
{
return m_pid;
}
ErrorOr<void> Process::disown()
{
if (m_pid != 0 && m_should_disown) {