[GO] I learned about processes in Python

Overview

--A memo that relearned around process generation using python --There is also a subprocess module, but a memo that I implemented and re-studied myself --Memorandum


Premise

--Environment - python: v.3.7.7


Basics

  1. Create a new session.
  2. Make the calling process the leader of a new session.
  3. Detach the process from the control terminal.

application

--In django, implementation example when you want to run the process as a long-time job even after returning the request - double fork --Experiment --Once fork and runscript-> Parent does not wait`` return → Naturally child process becomes zombie --If you fork twice, the grandchild process becomes a child process under init → The grandchild process ends → *** It disappears without becoming a zombie *** --Kimo has the grandchild process daemonized because setsid () is working.

  1. The child process becomes the session leader after fork and has a control terminal separate from the parent process.
  2. Child process fork grandchild process
  3. The child process immediately ʻexit ()and the parent process waits withwaitpid → prevent the child process from being kill and zombied
  4. It is obvious that the grandchild process is not a session leader, so it is promised not to have a control terminal as a daemon
  5. When the child process ends, the grandchild process will post-process the process under the init process (root), so it will not become a zombie after the process ends. --About sessions and processes --All processes belong to the group that belongs to the session, and there is a hierarchy. --Session (SID) → Process group (PGID) → Process (PID) --The first process in a process group becomes the process group leader --The first process in a session becomes the session leader --A single TTY is associated with every session, and only the session leader can control the TTY. --In order for the process to be daemonized (run in the background), the session leader must be kill so that the session cannot control the TTY.

Recommended Posts

I learned about processes in Python
What I learned in Python
About __all__ in python
I investigated in detail about variable processing in python
I wrote python in Japanese
Refactoring Learned in Python (Basic)
Python classes learned in chemoinformatics
What I learned about Linux
I understand Python in Japanese!
I learned Python basic grammar
Character code learned in Python
Python functions learned in chemoinformatics
About "for _ in range ():" in python
What I learned about AI / machine learning using Python (1)
What I learned about AI / machine learning using Python (3)
What I learned about AI / machine learning using Python (2)
About dtypes in Python and Cython
What I learned about AI and machine learning using Python (4)
I wrote Fizz Buzz in Python
I can't install scikit-learn in Python
Elementary ITK usage learned in Python
I wrote the queue in Python
I tried Line notification in Python
I wrote the stack in Python
I put Python 2.7 in Sakura VPS 1GB.
Basic Linear Algebra Learned in Python (Part 1)
I tried to implement PLSA in Python
I tried to implement permutation in Python
I made a payroll program in Python!
I tried using Bayesian Optimization in Python
I can't debug python scripts in Eclipse
I implemented Cousera's logistic regression in Python
Exclusive file access between processes in Python
I tried to implement ADALINE in Python
I wanted to solve ABC159 in Python
I tried to implement PPO in Python
I searched for prime numbers in python
I created a password tool in Python.
Why can't I install matplotlib in python! !!
About python slices
Python in optimization
CURL in python
Metaprogramming in Python
Python 3.3 in Anaconda
Geocoding in python
Meta-analysis in Python
Unittest in python
About python yield
About python, class
I started python
Epoch in Python
Discord in Python
Sudoku in Python
DCI in Python
quicksort in python
nCr in python
N-Gram in Python
Programming in python
Plink in Python
Constant in python
About python decorators