Loading [MathJax]/extensions/tex2jax.js
GammaLib
2.0.0
Toggle main menu visibility
Main Page
Related Pages
Namespaces
Namespace List
Namespace Members
All
a
c
d
e
f
g
h
i
l
m
n
o
p
r
s
t
w
x
Functions
a
c
d
e
f
g
h
i
l
m
n
p
r
s
t
w
x
Variables
d
e
f
g
i
l
m
o
p
r
s
t
Classes
Class List
Class Index
Class Hierarchy
Class Members
All
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
q
r
s
t
u
v
w
x
y
z
~
Functions
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
q
r
s
t
u
v
w
x
y
z
~
Variables
a
d
e
f
h
i
l
m
n
p
r
s
u
v
Enumerations
Enumerator
Related Symbols
a
c
e
g
i
l
m
n
o
p
s
t
Files
File List
File Members
All
_
a
c
d
e
f
g
h
i
j
l
m
n
o
p
r
s
t
u
v
Functions
_
a
c
e
i
l
m
n
o
p
s
t
Variables
c
d
g
j
m
n
o
r
s
t
u
Typedefs
Enumerations
Enumerator
Macros
_
c
d
f
g
h
n
u
▼
GammaLib
Todo List
►
Namespaces
►
Classes
▼
Files
▼
File List
►
include
►
inst
▼
src
►
app
►
base
►
fits
►
linalg
►
model
►
numerics
►
obs
►
opt
►
sky
►
support
►
test
►
vo
►
xml
►
xspec
►
gammalibd.cpp
►
File Members
•
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
Pages
Loading...
Searching...
No Matches
gammalibd.cpp
Go to the documentation of this file.
1
/***************************************************************************
2
* gammalibd.cpp - GammaLib daemon launcher *
3
* ----------------------------------------------------------------------- *
4
* copyright (C) 2022 by Juergen Knoedlseder *
5
* ----------------------------------------------------------------------- *
6
* *
7
* This program is free software: you can redistribute it and/or modify *
8
* it under the terms of the GNU General Public License as published by *
9
* the Free Software Foundation, either version 3 of the License, or *
10
* (at your option) any later version. *
11
* *
12
* This program is distributed in the hope that it will be useful, *
13
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
14
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
15
* GNU General Public License for more details. *
16
* *
17
* You should have received a copy of the GNU General Public License *
18
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
19
* *
20
***************************************************************************/
21
/**
22
* @file gammalibd.cpp
23
* @brief GammaLib daemon launcher
24
* @author Juergen Knoedlseder
25
*/
26
27
/* __ Includes ___________________________________________________________ */
28
#ifdef HAVE_CONFIG_H
29
#include <config.h>
30
#endif
31
#include <fcntl.h>
// for file locking
32
#include <unistd.h>
// access() function
33
#include <cstdlib>
// exit() function
34
#include <cstdio>
// std::fopen(), etc. functions
35
#include <signal.h>
// signal() function
36
#include "
GammaLib.hpp
"
// make GammaLib classes available
37
38
39
/***********************************************************************/
/**
40
* @brief GammaLib daemon launcher
41
*
42
* This executable launched the GammaLib daemon. Calling this executable
43
* during the initialisation of GammaLib will launch a daemon that has the
44
* correct process name on all platforms.
45
***************************************************************************/
46
int
main
(
void
) {
47
48
// Initialise daemon
49
GDaemon
daemon;
50
51
// If daemon is not alive then create instance
52
if
(!daemon.
alive
()) {
53
54
// Create child process to start the daemon. Do nothing if child
55
// process creation fails.
56
int
pid = fork();
57
if
(pid >= 0) {
58
59
// If we have a PID of 0 we are in the child process. In this
60
// case we create and start the daemon ...
61
if
(pid == 0) {
62
63
// The child process becomes session leader
64
setsid();
65
66
// Ignore signals
67
signal(SIGCHLD, SIG_IGN);
// Ignore if child has stopped
68
signal(SIGHUP, SIG_IGN);
// Ignore death of controlling process
69
signal(SIGTERM, SIG_IGN);
// Ignore termination signal
70
71
// Fork for the second time and let the first fork
72
// process terminate
73
pid = fork();
74
if
(pid >= 0) {
75
if
(pid == 0) {
76
GDaemon
daemon;
77
daemon.
start
();
78
exit(EXIT_SUCCESS);
79
}
80
}
// endif: child of child process created
81
82
}
83
84
}
// endif: child proces created
85
86
}
// endif: daemon
87
88
// Always exit with success
89
return
EXIT_SUCCESS;
90
}
46
int
main
(
void
) {
…
}
GammaLib.hpp
GammaLib definitions.
GDaemon
Daemon class.
Definition
GDaemon.hpp:51
GDaemon::start
void start(void)
Starts the daemon.
Definition
GDaemon.cpp:177
GDaemon::alive
bool alive(void) const
Check if daemon is alive.
Definition
GDaemon.cpp:282
main
int main(void)
GammaLib daemon launcher.
Definition
gammalibd.cpp:46
src
gammalibd.cpp
Generated on Tue Jan 14 2025 15:02:58 for GammaLib by
1.11.0