daemonize_8c-source.html
3.16 KB
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
40
41
42
43
44
45
46
47
48
49
50
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html><head><meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
<title>xmlrpc: system/daemonize.c Source File</title>
<link href="tabs.css" rel="stylesheet" type="text/css">
<link href="doxygen.css" rel="stylesheet" type="text/css">
</head><body>
<!-- Generated by Doxygen 1.5.8 -->
<div class="navigation" id="top">
<div class="tabs">
<ul>
<li><a href="main.html"><span>Main Page</span></a></li>
<li><a href="annotated.html"><span>Data Structures</span></a></li>
<li class="current"><a href="files.html"><span>Files</span></a></li>
</ul>
</div>
<div class="tabs">
<ul>
<li><a href="files.html"><span>File List</span></a></li>
<li><a href="globals.html"><span>Globals</span></a></li>
</ul>
</div>
<h1>system/daemonize.c</h1><a href="daemonize_8c.html">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="preprocessor">#include <stdio.h></span> <span class="comment">/* for printf() and fprintf() */</span>
<a name="l00002"></a>00002 <span class="preprocessor">#include <unistd.h></span> <span class="comment">/* for getopt */</span>
<a name="l00003"></a>00003 <span class="preprocessor">#include <stdlib.h></span>
<a name="l00004"></a>00004
<a name="l00005"></a>00005
<a name="l00006"></a><a class="code" href="daemonize_8c.html#29b0af1da2432bcc90721c0b62f4e660">00006</a> <span class="keywordtype">void</span> <a class="code" href="daemonize_8h.html#29b0af1da2432bcc90721c0b62f4e660">daemonize</a>(<span class="keywordtype">void</span>) {
<a name="l00007"></a>00007 pid_t pid;
<a name="l00008"></a>00008
<a name="l00009"></a>00009 <span class="keywordflow">if</span> (0 > ((pid = fork()))) {
<a name="l00010"></a>00010 perror(<span class="stringliteral">"deamoinze[fork]"</span>);
<a name="l00011"></a>00011 exit(EXIT_FAILURE);
<a name="l00012"></a>00012 } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (0 != pid) {
<a name="l00013"></a>00013 exit(EXIT_SUCCESS);
<a name="l00014"></a>00014 }
<a name="l00015"></a>00015
<a name="l00016"></a>00016 <span class="comment">/* make new child session leader */</span>
<a name="l00017"></a>00017 setsid();
<a name="l00018"></a>00018
<a name="l00019"></a>00019 <span class="comment">/* connect all standard streams to /dev/null */</span>
<a name="l00020"></a>00020 freopen(<span class="stringliteral">"/dev/null"</span>, <span class="stringliteral">"w"</span>, stderr);
<a name="l00021"></a>00021 freopen(<span class="stringliteral">"/dev/null"</span>, <span class="stringliteral">"r"</span>, stdin);
<a name="l00022"></a>00022 freopen(<span class="stringliteral">"/dev/null"</span>, <span class="stringliteral">"w"</span>, stdout);
<a name="l00023"></a>00023 }
</pre></div></div>
<hr size="1"><address style="text-align: right;"><small>Generated on Sun Oct 10 01:24:35 2010 for xmlrpc by
<a href="http://www.doxygen.org/index.html">
<img src="doxygen.png" alt="doxygen" align="middle" border="0"></a> 1.5.8 </small></address>
</body>
</html>