Linux process state
PROCESS STATE CODES
R running or runnable (on run queue)
D uninterruptible sleep (usually IO)
S interruptible sleep (waiting for an event to complete)
Z defunct/zombie, terminated but not reaped by its parent
T stopped, either by a job control signal or because it is being traced
A zombie process is a process that exited successfully, but its state change wasn't yet acknowledged by the parent. That is, the parent didn't call wait() / waitpid() functions.
signal
Signal Dispositions Each signal has a current disposition, which determines how the process behaves when it is delivered the signal.
Stop Default action is to stop the process. Cont Default action is to continue the process if it is currently stopped.
Signal Value Action Comment
──────────────────────────────────────────────────
SIGCONT 18 Cont Continue if stopped
SIGSTOP 19 Stop Stop process
通常情况下,pid 不是 parent id 而是 process ID!
import os
import signal
pid = os.fork()
# fork() itself is interesting. If a fork() returns zero, it means you're in the “child process”. If fork() returns a positive value - it's documented to return the PID of the child - you're in the parent and a child process has successfully “spawned”
if pid:
print("In parent process")
os.kill(pid, signal.SIGSTOP)
print("Signal sent, child stopped.")
info = os.waitpid(pid, os.WSTOPPED)
stopSignal = os.WSTOPSIG(info[1])
print("Child stopped due to signal no:", stopSignal)
print("Signal name:", signal.Signals(stopSignal).name)
# send signal 'SIGCONT'
os.kill(pid, signal.SIGCONT)
print("\nSignal sent, child continued.")
else:
print("\nIn child process")
print("Process ID:", os.getpid())
print("Hello ! Geeks")
print("Exiting")
阿 所以严格意义上讲, kill 是 send signal 的,而不是杀死。好糟糕的方法名!