Last change
on this file since 65 was
17,
checked in by retracile, 15 years ago
|
Mergebot: redesigned implementation. Still has rough edges.
|
File size:
513 bytes
|
Line | |
---|
1 | """Implementation of the daemonizing process |
---|
2 | from "Advanced Programming in the UNIX Environment" by W. Richard Stevens, |
---|
3 | 1993. |
---|
4 | """ |
---|
5 | import os |
---|
6 | import sys |
---|
7 | |
---|
8 | def daemonize(): |
---|
9 | # Let's assume nothing ever goes wrong... |
---|
10 | pid = os.fork() |
---|
11 | if pid: |
---|
12 | sys.exit(0) |
---|
13 | os.setsid() |
---|
14 | os.chdir('/') |
---|
15 | os.umask(000) |
---|
16 | for n in range(1024): |
---|
17 | try: |
---|
18 | os.close(n) |
---|
19 | except OSError: |
---|
20 | pass |
---|
21 | os.open('/dev/null', os.O_RDONLY) |
---|
22 | os.open('/dev/null', os.O_WRONLY) |
---|
23 | os.dup(1) |
---|
Note: See
TracBrowser
for help on using the repository browser.