forked from sony/nmos-cpp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprocess_utils.cpp
39 lines (35 loc) · 1.1 KB
/
process_utils.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#include "nmos/process_utils.h"
#include <boost/asio/io_service.hpp>
#include <boost/asio/signal_set.hpp>
// boost::this_process::get_id() would be perfect, except that Boost.Process was only introduced in Boost 1.64.0
// and VS2013 chokes on boost/process/detail/config.hpp (tested at Boost.1.65.1)
#if defined(_WIN32)
extern "C" __declspec(dllimport) unsigned long __stdcall GetCurrentProcessId();
#else
#include <unistd.h>
#endif
namespace nmos
{
namespace details
{
// Get the current process ID
int get_process_id()
{
#if defined(_WIN32)
return GetCurrentProcessId();
#else
return getpid();
#endif
}
// Wait for a process termination signal
void wait_term_signal()
{
boost::asio::io_service service;
// On Windows, Ctrl+C generates SIGINT
// On Linux, the kill command generates SIGTERM by default
boost::asio::signal_set signals(service, SIGINT, SIGTERM);
signals.async_wait([](const boost::system::error_code&, int){});
service.run_one();
}
}
}