0

I am using apache + django(mod_wsgi) to do some job.

First, I write a simple bash script that will invoke terminal on X window, and executing some command. ex:

DISPLAY=:1 gnome-terminal -e 'sleep 9999' &

If I run this command/script in ssh session, it keep alive even I logout ssh session. However, if I execute this command in django python code. gnome-terminal will run and close immediately because its parent(apache session?) is exited?

How can I run such command(gnome-terminal -e 'cmd') by django + apache without kill it? Thanks a lot.

CSJ
  • 2,709
  • 4
  • 24
  • 30

1 Answers1

2

I guess the first question is "are you sure you want to do this?"

How are you attempting to start the process? If you are calling os.system it definitely won't survive, but if you are calling os.fork() and then os.execv I'd think it would survive. But, if that doesn't work, I think you could follow the standard process for daemonizing, which should work.

That's something like:

fork()
in child, close open file descriptors
open stderr, stdout, stdin (read from dev/null, write to dev/null perhaps) 
setsid()
chdir('/')
fork()
in child, exec the terminal.

See the discussion here on daemonizing: http://code.activestate.com/recipes/66012-fork-a-daemon-process-on-unix/

apg
  • 2,611
  • 1
  • 18
  • 19