Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7613927
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T02:16:20+00:00 2026-05-31T02:16:20+00:00

I am trying to spawn a django process that lives on after the calling

  • 0

I am trying to spawn a django process that lives on after the calling script died. But I need it’s PID.

So I wrote the following code:

def runserver():
  print("START PID: " + str(os.getpid()))
  pid = os.fork()

  if pid == 0:
      #cmd = "/usr/bin/env python manage.py runserver 0.0.0.0:2869"
      print("IN THE CHILD PID: " + str(os.getpid()))
      os.execvp("python", ["", "manage.py", "runserver", "0.0.0.0:2869"])
  else:
      print("PARENT PID: " + str(os.getpid()))
      print("CHILD PID: " + str(pid))
      updatepid("runserver", pid) 

This gives me the following output:

START PID: 13019
PARENT PID: 13019
CHILD PID: 13020
IN THE CHILD PID: 13020

But now when I check the live processes:

> ps aux | grep python | grep -v grep
sandro   13031  0.4  0.3 296080 23756 pts/2    Sl   22:14   0:01 /home/sandro/.virtualenvs/polling/bin/python2.7 manage.py runserver 0.0.0.0:2869

The pid changed! What on earth is going on???

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T02:16:21+00:00Added an answer on May 31, 2026 at 2:16 am

    If you see the other PID then there is definitely a new process. You can easily find the place where the new process spawned. Start in django.core.management.commands.runserver and you’ll come to django.utils.autoreload.python_reloader. When python_reloader called first time in a process it goes to restart_with_reloader where you can see this:

    exit_code = os.spawnve(os.P_WAIT, sys.executable, args, new_environ)
    

    Thereby, with your script you get two processes: one where runserver is executing and one (spawned) with webserver. Check it:

    START PID: 3091
    PARENT PID: 3091
    CHILD PID: 3092
    IN THE CHILD PID: 3092
    
    $ ps ax | grep runserver | grep -v grep
    3092 pts/1    S      0:00  runserver 0.0.0.0:2869
    3093 pts/1    Sl     0:05 /home/kirill/testenv/bin/python manage.py runserver 0.0.0.0:2869
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to spawn a process that executes a system command, while my
I'm trying to spawn a child process to do some backend cleanup work after
I am trying to spawn a process using Runtime.exec. I want to use my
I am trying to spawn a thread to take care of DoWork task that
I'm trying to get this simple windows dialog to spawn but as soon as
I am trying to run daemon process using daemon-spawn gem. Here is the code
I'm trying to set up a simple producer-consumer system in Gevent but my script
I'm trying to spawn a new process from my C++-project using fork-exec. I'm using
I am trying to spawn a new process using execve() from unistd.h on Linux.
I am trying to figure out how to spawn a process / start an

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.