1//===-- HostProcessPosix.cpp ----------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#include "lldb/Host/Host.h"
10#include "lldb/Host/FileSystem.h"
11#include "lldb/Host/posix/HostProcessPosix.h"
12
13#include "llvm/ADT/STLExtras.h"
14
15#include <climits>
16#include <csignal>
17#include <unistd.h>
18
19using namespace lldb_private;
20
21static const int kInvalidPosixProcess = 0;
22
23HostProcessPosix::HostProcessPosix()
24 : HostNativeProcessBase(kInvalidPosixProcess) {}
25
26HostProcessPosix::HostProcessPosix(lldb::process_t process)
27 : HostNativeProcessBase(process) {}
28
29HostProcessPosix::~HostProcessPosix() = default;
30
31Status HostProcessPosix::Signal(int signo) const {
32 if (m_process == kInvalidPosixProcess) {
33 return Status::FromErrorString(
34 str: "HostProcessPosix refers to an invalid process");
35 }
36
37 return HostProcessPosix::Signal(process: m_process, signo);
38}
39
40Status HostProcessPosix::Signal(lldb::process_t process, int signo) {
41 Status error;
42
43 if (-1 == ::kill(pid: process, sig: signo))
44 return Status::FromErrno();
45
46 return error;
47}
48
49Status HostProcessPosix::Terminate() { return Signal(SIGKILL); }
50
51lldb::pid_t HostProcessPosix::GetProcessId() const { return m_process; }
52
53bool HostProcessPosix::IsRunning() const {
54 if (m_process == kInvalidPosixProcess)
55 return false;
56
57 // Send this process the null signal. If it succeeds the process is running.
58 Status error = Signal(signo: 0);
59 return error.Success();
60}
61
62llvm::Expected<HostThread> HostProcessPosix::StartMonitoring(
63 const Host::MonitorChildProcessCallback &callback) {
64 return Host::StartMonitoringChildProcess(callback, pid: m_process);
65}
66

Provided by KDAB

Privacy Policy
Learn to use CMake with our Intro Training
Find out more

source code of lldb/source/Host/posix/HostProcessPosix.cpp