ChimeraTK-DeviceAccess
03.25.00
Loading...
Searching...
No Matches
ProcessManagement.cpp
Go to the documentation of this file.
1
// SPDX-FileCopyrightText: Deutsches Elektronen-Synchrotron DESY, MSK, ChimeraTK Project <chimeratk-support@desy.de>
2
// SPDX-License-Identifier: LGPL-3.0-or-later
3
4
#include "
ProcessManagement.h
"
5
6
#include <sys/types.h>
7
8
#include <pwd.h>
9
#include <unistd.h>
10
11
#include <cerrno>
12
#include <csignal>
13
#include <cstring>
14
#include <iostream>
15
#include <string>
16
17
bool
processExists
(
unsigned
pid) {
18
return
!kill((pid_t)pid, 0);
19
}
20
21
unsigned
getOwnPID
() {
22
return
(
unsigned
)getpid();
23
}
24
25
std::string
getUserName
() {
26
errno = 0;
27
auto
* pwent = getpwuid(geteuid());
28
auto
savedErr = errno;
29
30
if
(pwent ==
nullptr
) {
31
// pwent == nullptr and errno == 0 is a valid scenario - There was no error, but the system also
32
// could not find the corresponding user name.
33
if
(savedErr != 0) {
34
std::cout <<
"Failed to lookup user name, expect issues: "
<< strerror(savedErr) << std::endl;
35
}
36
return
{
"**unknown*user*name**"
};
37
}
38
return
{pwent->pw_name};
39
}
getUserName
std::string getUserName()
Definition
ProcessManagement.cpp:25
processExists
bool processExists(unsigned pid)
Definition
ProcessManagement.cpp:17
getOwnPID
unsigned getOwnPID()
Definition
ProcessManagement.cpp:21
ProcessManagement.h
sources
ChimeraTK-DeviceAccess
src
ProcessManagement.cpp
Generated by
1.9.8