Python os.kill() Method
Example
Send a signal to the specified process id:
# importing os and signal Library
import os, signal
# Create a child process
pid = os.fork()
# pid greater than 0 denotes the parent process
if pid :
print("\nIn parent process")
# send signal 'SIGSTOP' to the child process
# 'SIGSTOP' signal causes the process to stop
os.kill(pid, signal.SIGSTOP)
print("Child stopped...")
else :
print("\nIn child process")
print("Process ID:", os.getpid())
Try it Yourself »
Definition and Usage
The os.kill() method sends a signal to the process with
the specified process id.
Constants for the specific signals are defined in the signal module.
Syntax
os.kill(pid, sig)
Parameter Values
| Parameter | Description |
|---|---|
| pid | Required. Specifies a process id to which signal is to be sent |
| sig | Required. Specifies a signal number or a signal constant to be sent |
Technical Details
| Return Value: | None |
|---|---|
| Python Version: | pre-2.6 |
| Change Log: | 3.2- Windows support |