[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Do any one know how to make a daemon in python



On Mon, Dec 24, 2007 at 09:22:55AM +0200, moayyad sadi wrote:
> > In Python, you can use os.fork() and os.setsid() which are the substitutes
> > of C's fork() and setsid() (of course, you need to import os library).
> >
> >
> I tried that
> it did not work,
> I write a small script that do
> from os import *
> from time import * # or something like that
> def loop():
>   for i in xrange(65000): print i; sleep(i)
> #main
> p=fork()
> if p==0: loop()
> else: print "this is the parent, child pid=%d\ndone\n" % p
> 
> and when I run it then close the terminal then open another one and type
> ps ax | grep python
> it did not appear
> 
> while the same code in C works
> 

You need to fork() twice!!
Check the link I sent earlier.

-- 
GPG-Key: 0xA3FD0DF7 - 9F73 032E EAC9 F7AD 951F  280E CB66 8E29 A3FD 0DF7
Debian User and Developer.
Homepage: www.foolab.org

Attachment: signature.asc
Description: Digital signature