Linux process management(1)

LORY
2 min readFeb 7, 2021

--

Process life cycle

fork and exec

Fork : Create a separate duplicated process (child process memory space copied from parent )

Exec : create a process replace current entire process (replace pid)

creation

All process created from parent process except ‘init’

Init process created by os kernel , id= 1 , which is the root process (systemd)

Subprocess.popen and os.fock in python

subprocess.Popen execute an arbitrary program/command/executable/whatever in its own process.

os.fork only allows you to create a child process that will execute the same script from the exact line in which you called it. As its name suggests, it “simply” forks the current process into 2.

os.fork is only available on Unix, and subprocess.Popen is cross-platfrom.

process scheduler (CFS)

- Pick lowest vuntime task

- Use red-black tree store task (log(n) lookup time),left vruntime node less than right node .so the left most node is the task with least vruntime

process management commands

bg = send stopped process to backgroundcommand & = run process in backgroundctrl+z = stop current process and put to jobsctrl+c = cancel process (remove from jobs)jobs = list all jobsfg %3 = bring 3rd job to fore groundkill — 15 pid = send signal ‘sigterm’kill -9 pid = kill signal ‘sigkill’ to processnice = run command with defined priority (-20 highest, 19 lowest)renice = modify process priority . renice +x 18471

--

--

LORY

A channel which focusing on developer growth and self improvement