2

I run this python file to spawn a process:

import os
import pwd
import subprocess
import sys


p = subprocess.Popen(['python', 'process_script.py'],
                     cwd="/execute",
                     stdout=subprocess.PIPE,
                     stderr=subprocess.STDOUT)

process_script.py looks like this:

import time
import random
import string
import helper

#

def run():
    while True:
        filename = "/execute/" + "".join([random.choice(string.ascii_letters) for j in range(8)]) + ".txt"

        helper.execute(f"echo foo > {filename}")

        time.sleep(10)

#

run()

[EDIT] In fact ps shows no other processess, so it looks like the thread terminates... but how and why?

If I run process_script.py directly, the files are created.

Omroth
  • 883
  • 7
  • 24

1 Answers1

2

in Popen child process dies when the parent exits you can add p.wait() at the end of your first script to prevent parent from exiting. also this link is useful check it out! subprocess gets killed even with nohup

badger
  • 2,908
  • 1
  • 13
  • 32