Path: blob/main/contrib/llvm-project/lldb/source/Host/posix/HostProcessPosix.cpp
39607 views
//===-- HostProcessPosix.cpp ----------------------------------------------===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//78#include "lldb/Host/Host.h"9#include "lldb/Host/FileSystem.h"10#include "lldb/Host/posix/HostProcessPosix.h"1112#include "llvm/ADT/STLExtras.h"1314#include <climits>15#include <csignal>16#include <unistd.h>1718using namespace lldb_private;1920static const int kInvalidPosixProcess = 0;2122HostProcessPosix::HostProcessPosix()23: HostNativeProcessBase(kInvalidPosixProcess) {}2425HostProcessPosix::HostProcessPosix(lldb::process_t process)26: HostNativeProcessBase(process) {}2728HostProcessPosix::~HostProcessPosix() = default;2930Status HostProcessPosix::Signal(int signo) const {31if (m_process == kInvalidPosixProcess) {32Status error;33error.SetErrorString("HostProcessPosix refers to an invalid process");34return error;35}3637return HostProcessPosix::Signal(m_process, signo);38}3940Status HostProcessPosix::Signal(lldb::process_t process, int signo) {41Status error;4243if (-1 == ::kill(process, signo))44error.SetErrorToErrno();4546return error;47}4849Status HostProcessPosix::Terminate() { return Signal(SIGKILL); }5051lldb::pid_t HostProcessPosix::GetProcessId() const { return m_process; }5253bool HostProcessPosix::IsRunning() const {54if (m_process == kInvalidPosixProcess)55return false;5657// Send this process the null signal. If it succeeds the process is running.58Status error = Signal(0);59return error.Success();60}6162llvm::Expected<HostThread> HostProcessPosix::StartMonitoring(63const Host::MonitorChildProcessCallback &callback) {64return Host::StartMonitoringChildProcess(callback, m_process);65}666768