Prctl
provide.foundation.process.prctl
¶
TODO: Add module docstring.
Classes¶
Functions¶
get_name
¶
Get process name (PR_GET_NAME).
Returns:
| Type | Description |
|---|---|
str | None
|
Process name, or None if prctl is not available |
Raises:
| Type | Description |
|---|---|
PlatformError
|
If not on Linux or python-prctl not installed |
Example
from provide.foundation.process import get_name get_name() 'worker-1'
Source code in provide/foundation/process/prctl.py
has_prctl
¶
Check if prctl is available.
Returns:
| Type | Description |
|---|---|
bool
|
True if running on Linux and python-prctl is installed, False otherwise |
Example
from provide.foundation.process import has_prctl if has_prctl(): ... # Use prctl features ... pass
Source code in provide/foundation/process/prctl.py
is_linux
¶
Check if running on Linux.
Returns:
| Type | Description |
|---|---|
bool
|
True if running on Linux, False otherwise |
Example
from provide.foundation.process import is_linux is_linux() True
Source code in provide/foundation/process/prctl.py
set_death_signal
¶
Set signal to be sent to process when parent dies (PR_SET_PDEATHSIG).
This is useful for ensuring child processes are cleaned up when the parent terminates unexpectedly.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
signal
|
int
|
Signal number to send (e.g., signal.SIGTERM, signal.SIGKILL) |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if successful, False otherwise |
Raises:
| Type | Description |
|---|---|
PlatformError
|
If not on Linux or python-prctl not installed |
Example
import signal from provide.foundation.process import set_death_signal set_death_signal(signal.SIGTERM) # Send SIGTERM when parent dies True
Source code in provide/foundation/process/prctl.py
set_dumpable
¶
Set whether process can produce core dumps (PR_SET_DUMPABLE).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dumpable
|
bool
|
True to allow core dumps, False to disable |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if successful, False otherwise |
Raises:
| Type | Description |
|---|---|
PlatformError
|
If not on Linux or python-prctl not installed |
Example
from provide.foundation.process import set_dumpable set_dumpable(False) # Disable core dumps for security True
Source code in provide/foundation/process/prctl.py
set_name
¶
Set process name (PR_SET_NAME).
Note: This is different from setproctitle. PR_SET_NAME sets the comm value in /proc/[pid]/comm (limited to 16 bytes including null terminator).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Process name (max 15 characters) |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if successful, False otherwise |
Raises:
| Type | Description |
|---|---|
PlatformError
|
If not on Linux or python-prctl not installed |
Example
from provide.foundation.process import set_name set_name("worker-1") True
Source code in provide/foundation/process/prctl.py
set_no_new_privs
¶
Set no_new_privs flag (PR_SET_NO_NEW_PRIVS).
When enabled, execve() will not grant privileges to do anything that could not have been done without the execve() call. This is a security feature.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
enabled
|
bool
|
True to enable no_new_privs, False to attempt disable (usually fails) |
True
|
Returns:
| Type | Description |
|---|---|
bool
|
True if successful, False otherwise |
Raises:
| Type | Description |
|---|---|
PlatformError
|
If not on Linux or python-prctl not installed |
Example
from provide.foundation.process import set_no_new_privs set_no_new_privs(True) # Prevent privilege escalation True