XSV_SOLJA Posted March 28, 2011 Share Posted March 28, 2011 Hi, is there anyone interested in helping me with a python project? It's a small script to give root access to a remote pc over internet, im not very good and have lost practice.. Quote Link to comment Share on other sites More sharing options...
XSV_SOLJA Posted April 6, 2011 Author Share Posted April 6, 2011 (edited) okay okay you want the source code beginging: it gives an error with 'pid = os.fork()' and says module doesnt have 'fork' import sys from socket import * import string import os import time import popen2 import signal def daemonize(): pid = os.fork() if(pid != 0): os._exit(0) ...and a whole lot of code... ending: im guessing that once above error is fixed this will come as well. it just says that 'daemonize()' has an error, and no discription if __name__ == "__main__": daemonize() main() Edited April 6, 2011 by XSV_SOLJA Quote Link to comment Share on other sites More sharing options...
Administrators daredevil Posted April 6, 2011 Administrators Share Posted April 6, 2011 I think Aigle/Gao is good at python and I am not sure who anyone else is here. Quote Link to comment Share on other sites More sharing options...
Aigle Posted April 6, 2011 Share Posted April 6, 2011 I would need a little bit more information... What OS are you trying to run this script on? What python version are you using? If I had to debug the code, I would try to use a script already done with the fork() function to know if you have it on your system. So try this code: #!/usr/bin/env python import os, sys print "I'm going to fork now - the child will write something to a pipe, and the parent will read it back" r, w = os.pipe() # these are file descriptors, not file objects pid = os.fork() if pid: # we are the parent os.close(w) # use os.close() to close a file descriptor r = os.fdopen(r) # turn r into a file object print "parent: reading" txt = r.read() os.waitpid(pid, 0) # make sure the child process gets cleaned up else: # we are the child os.close(r) w = os.fdopen(w, 'w') print "child: writing" w.write("here's some text from the child") w.close() print "child: closing" sys.exit(0) print "parent: got it; text =", txt Copy/paste from http://www.myelin.co...post/2003/3/13/ It works perfectly on my Suse box: [17:08:13 root@jodion.rp10:~ ()]# ./test.py I'm going to fork now - the child will write something to a pipe, and the parent will read it back parent: reading child: writing child: closing parent: got it; text = here's some text from the child From the Python docs: os.fork() Fork a child process. Return 0 in the child and the child’s process id in the parent. If an error occurs OSError is raised. Note that some platforms including FreeBSD <= 6.3, Cygwin and OS/2 EMX have known issues when using fork() from a thread. Availability: Unix. So if you are using Windows + cygwin, it might not work perfectly... Quote Link to comment Share on other sites More sharing options...
XSV_SOLJA Posted April 7, 2011 Author Share Posted April 7, 2011 therefore i hate windows ..no wait even more reason to get a nix box Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.