API
Easy process freeze & thaw
cli
Command-line entry point for pdum-criu utilities.
doctor()
Run environment diagnostics and report missing prerequisites.
Notes
- Always exits on non-Linux hosts because CRIU requires Linux kernel support.
- Prints a checklist showing which requirements passed or failed.
Raises:
| Type | Description |
|---|---|
Exit
|
Raised when the platform is unsupported or after reporting failed checks. |
Source code in src/pdum/criu/cli.py
433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 | |
main_callback(ctx)
Fallback handler when no top-level subcommand is invoked.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ctx
|
Context
|
Current Typer context used to detect whether a subcommand was chosen. |
required |
Raises:
| Type | Description |
|---|---|
Exit
|
Raised to stop execution after printing the autogenerated help text. |
Source code in src/pdum/criu/cli.py
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 | |
shell_beam(images_dir=typer.Option(None, '--dir', '-d', help='Optional directory for the CRIU image set (defaults to a temp dir).'), pid=typer.Option(None, '--pid', help='PID to beam.'), pgrep=typer.Option(None, '--pgrep', help='pgrep pattern to resolve the PID.'), log_file=typer.Option(None, '--log-file', '-l', help='Optional log file override for the freeze phase.'), verbosity=typer.Option(4, '--verbosity', '-v', min=0, max=4, help='CRIU verbosity level.'), leave_running=typer.Option(True, '--leave-running/--no-leave-running', help='Keep the target process running after dump completes.'), cleanup=typer.Option(True, '--cleanup/--no-cleanup', help='Remove the image directory once the beamed process exits.'), show_command=typer.Option(True, '--show-command/--hide-command', help='Print each CRIU command before executing it.'), pidfile=typer.Option(None, '--pidfile', help='Path where CRIU writes the restored PID (defaults to a temp file in the image dir).'))
Freeze a shell and immediately thaw it ("beam" workflow).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
images_dir
|
Path
|
Directory for CRIU artifacts. A temporary directory is created when omitted. |
Option(None, '--dir', '-d', help='Optional directory for the CRIU image set (defaults to a temp dir).')
|
pid
|
int
|
Explicit PID to beam. Mutually exclusive with |
Option(None, '--pid', help='PID to beam.')
|
pgrep
|
str
|
|
Option(None, '--pgrep', help='pgrep pattern to resolve the PID.')
|
log_file
|
Path
|
Override for the freeze-phase log file. |
Option(None, '--log-file', '-l', help='Optional log file override for the freeze phase.')
|
verbosity
|
int
|
CRIU verbosity level between 0 and 4. |
Option(4, '--verbosity', '-v', min=0, max=4, help='CRIU verbosity level.')
|
leave_running
|
bool
|
If |
Option(True, '--leave-running/--no-leave-running', help='Keep the target process running after dump completes.')
|
cleanup
|
bool
|
Remove the image directory after the beamed process exits. |
Option(True, '--cleanup/--no-cleanup', help='Remove the image directory once the beamed process exits.')
|
show_command
|
bool
|
When |
Option(True, '--show-command/--hide-command', help='Print each CRIU command before executing it.')
|
pidfile
|
Path
|
Location where CRIU writes the restored PID. Defaults to a temp file in |
Option(None, '--pidfile', help='Path where CRIU writes the restored PID (defaults to a temp file in the image dir).')
|
Raises:
| Type | Description |
|---|---|
Exit
|
Raised when freezing or restoring fails, or if prerequisites are missing. |
Source code in src/pdum/criu/cli.py
285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 | |
shell_callback(ctx)
Display shell helper usage when no subcommand is provided.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ctx
|
Context
|
Current Typer context describing the shell command invocation. |
required |
Raises:
| Type | Description |
|---|---|
Exit
|
Raised to stop execution after emitting help text. |
Source code in src/pdum/criu/cli.py
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 | |
shell_freeze(images_dir=typer.Option(..., '--dir', '-d', help='Directory that will contain the CRIU image set.'), pid=typer.Option(None, '--pid', help='PID to freeze.'), pgrep=typer.Option(None, '--pgrep', help='pgrep pattern to resolve the PID.'), log_file=typer.Option(None, '--log-file', '-l', help='Optional log file override (default: freeze.<pid>.log inside the image dir).'), verbosity=typer.Option(4, '--verbosity', '-v', min=0, max=4, help='CRIU verbosity level (0-4).'), leave_running=typer.Option(True, '--leave-running/--no-leave-running', help='Keep the target process running after dump completes.'), show_command=typer.Option(True, '--show-command/--hide-command', help='Print the CRIU command before executing it.'), show_tail=typer.Option(True, '--show-tail/--hide-tail', help='Display the last five lines of the freeze log after success.'), validate_tty=typer.Option(True, '--validate-tty/--no-validate-tty', help='Fail fast if the process is using an unsupported terminal (e.g., VS Code).'))
Checkpoint a running shell/job into a CRIU image directory.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
images_dir
|
Path
|
Target directory that will contain the CRIU image set (created if needed). |
Option(..., '--dir', '-d', help='Directory that will contain the CRIU image set.')
|
pid
|
int
|
Explicit PID to freeze. Mutually exclusive with |
Option(None, '--pid', help='PID to freeze.')
|
pgrep
|
str
|
|
Option(None, '--pgrep', help='pgrep pattern to resolve the PID.')
|
log_file
|
Path
|
Override for the CRIU log (defaults to |
Option(None, '--log-file', '-l', help='Optional log file override (default: freeze.<pid>.log inside the image dir).')
|
verbosity
|
int
|
CRIU verbosity level between 0 and 4. |
Option(4, '--verbosity', '-v', min=0, max=4, help='CRIU verbosity level (0-4).')
|
leave_running
|
bool
|
Whether to keep the target process alive after the dump completes. |
Option(True, '--leave-running/--no-leave-running', help='Keep the target process running after dump completes.')
|
show_command
|
bool
|
When |
Option(True, '--show-command/--hide-command', help='Print the CRIU command before executing it.')
|
show_tail
|
bool
|
When |
Option(True, '--show-tail/--hide-tail', help='Display the last five lines of the freeze log after success.')
|
validate_tty
|
bool
|
Fail fast if the process is attached to an unsupported TTY (e.g., VS Code). |
Option(True, '--validate-tty/--no-validate-tty', help='Fail fast if the process is using an unsupported terminal (e.g., VS Code).')
|
Raises:
| Type | Description |
|---|---|
Exit
|
Raised when validation fails or CRIU exits with a non-zero status. |
Source code in src/pdum/criu/cli.py
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 | |
shell_thaw(images_dir=typer.Option(..., '--dir', '-d', help='CRIU image directory to restore.'), show_command=typer.Option(True, '--show-command/--hide-command', help='Print the CRIU command before executing it.'), pidfile=typer.Option(None, '--pidfile', help='Path where CRIU writes the restored PID (defaults to a temp file in the image dir).'))
Restore a shell/job from a CRIU image directory.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
images_dir
|
Path
|
Directory that contains the CRIU image set to restore. |
Option(..., '--dir', '-d', help='CRIU image directory to restore.')
|
show_command
|
bool
|
When |
Option(True, '--show-command/--hide-command', help='Print the CRIU command before executing it.')
|
pidfile
|
Path
|
Location where CRIU writes the restored PID. Defaults to a temporary file inside |
Option(None, '--pidfile', help='Path where CRIU writes the restored PID (defaults to a temp file in the image dir).')
|
Raises:
| Type | Description |
|---|---|
Exit
|
Raised when prerequisites are missing or CRIU restoration fails. |
Source code in src/pdum/criu/cli.py
215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 | |
version_command()
Display the CLI version banner.
Notes
This command always succeeds and prints the current pdum-criu package version.
Source code in src/pdum/criu/cli.py
85 86 87 88 89 90 91 92 93 94 95 96 | |
goblins
Utility APIs for freezing and thawing goblin processes.
AsyncGoblinProcess
dataclass
Async counterpart returned by :func:thaw_async.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
helper_pid
|
int | None
|
PID of the helper process ( |
required |
stdin
|
StreamWriter
|
Writable pipe towards the goblin's stdin. |
required |
stdout
|
StreamReader
|
Readers for stdout/stderr respectively. |
required |
stderr
|
StreamReader
|
Readers for stdout/stderr respectively. |
required |
images_dir
|
Path
|
Directory containing the image set. |
required |
log_path
|
Path
|
CRIU restore log path. |
required |
pidfile
|
Path
|
File CRIU uses to publish the restored PID. |
required |
Source code in src/pdum/criu/goblins/__init__.py
235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 | |
read_pidfile()
async
Asynchronously return the PID recorded by CRIU.
Source code in src/pdum/criu/goblins/__init__.py
263 264 265 266 267 | |
GoblinProcess
dataclass
Synchronous handle returned by :func:thaw.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
helper_pid
|
int | None
|
PID of the helper process ( |
required |
stdin
|
BufferedWriter
|
Binary file objects connected to the goblin's stdio pipes. |
required |
stdout
|
BufferedWriter
|
Binary file objects connected to the goblin's stdio pipes. |
required |
stderr
|
BufferedWriter
|
Binary file objects connected to the goblin's stdio pipes. |
required |
images_dir
|
Path
|
Directory that contains the CRIU image set used for this restore. |
required |
log_path
|
Path
|
Path to the CRIU restore log file. |
required |
pidfile
|
Path
|
Path CRIU populates with the restored process PID. |
required |
Source code in src/pdum/criu/goblins/__init__.py
193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 | |
read_pidfile()
Return the PID recorded by CRIU.
Source code in src/pdum/criu/goblins/__init__.py
219 220 221 222 | |
freeze(pid, images_dir, *, leave_running=True, log_path=None, verbosity=4, extra_args=None, shell_job=True)
Checkpoint a goblin process into the specified image directory.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pid
|
int
|
PID of the goblin process to dump. |
required |
images_dir
|
str | Path
|
Directory that will store the CRIU image set. |
required |
leave_running
|
bool
|
Whether to keep the goblin running after the dump completes. Defaults to True. |
True
|
log_path
|
str | Path
|
Optional path for CRIU's log file. Defaults to |
None
|
verbosity
|
int
|
CRIU verbosity level (0-4). Defaults to 4 to aid troubleshooting. |
4
|
extra_args
|
Iterable[str]
|
Additional CRIU arguments to append verbatim. |
None
|
shell_job
|
bool
|
Whether to include |
True
|
Returns:
| Type | Description |
|---|---|
Path
|
Path to the CRIU log file for the dump operation. |
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If CRIU fails to dump the process. |
ValueError
|
If |
Source code in src/pdum/criu/goblins/__init__.py
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 | |
freeze_async(pid, images_dir, *, leave_running=True, log_path=None, verbosity=4, extra_args=None, shell_job=True)
async
Asynchronously checkpoint a goblin process with CRIU.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pid
|
int
|
PID of the goblin process to dump. |
required |
images_dir
|
str | Path
|
Directory that will store the CRIU image set. |
required |
leave_running
|
bool
|
Keep the goblin alive after dumping. Defaults to True. |
True
|
log_path
|
str | Path
|
Path for CRIU's log file. Defaults to |
None
|
verbosity
|
int
|
CRIU verbosity level (0-4). Defaults to 4. |
4
|
extra_args
|
Iterable[str]
|
Additional CRIU arguments to append verbatim. |
None
|
shell_job
|
bool
|
Whether to pass |
True
|
Returns:
| Type | Description |
|---|---|
Path
|
Path to the CRIU log file for the dump operation. |
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If CRIU fails to dump the process. |
ValueError
|
If |
Source code in src/pdum/criu/goblins/__init__.py
122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 | |
thaw(images_dir, *, extra_args=None, log_path=None, pidfile=None, shell_job=True, detach=False)
Restore a goblin synchronously and reconnect to its pipes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
images_dir
|
str | Path
|
Directory containing the CRIU image set to restore. |
required |
extra_args
|
Iterable[str]
|
Additional CRIU restore arguments to append verbatim. |
None
|
log_path
|
str | Path
|
Override for the CRIU restore log file. Defaults to |
None
|
pidfile
|
str | Path
|
Override for the CRIU |
None
|
shell_job
|
bool
|
Whether to run CRIU with |
True
|
detach
|
bool
|
Whether to pass |
False
|
Returns:
| Type | Description |
|---|---|
GoblinProcess
|
Handle that exposes stdio pipes plus metadata (log path, pidfile, helper pid).
Call :meth: |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
RuntimeError
|
If CRIU fails to start. |
Source code in src/pdum/criu/goblins/__init__.py
277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 | |
thaw_async(images_dir, *, extra_args=None, log_path=None, pidfile=None, shell_job=True, detach=False)
async
Async variant of :func:thaw that returns asyncio streams.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
images_dir
|
str | Path
|
Directory containing the CRIU image set to restore. |
required |
extra_args
|
Iterable[str]
|
Additional CRIU restore arguments to append verbatim. |
None
|
log_path
|
str | Path
|
Override for the CRIU restore log file path. |
None
|
pidfile
|
str | Path
|
Override for the CRIU |
None
|
shell_job
|
bool
|
Whether to include |
True
|
detach
|
bool
|
Whether to pass |
False
|
Returns:
| Type | Description |
|---|---|
AsyncGoblinProcess
|
Handle exposing asyncio streams plus metadata about the restore. Use
:meth: |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
RuntimeError
|
If CRIU fails to start. |
Source code in src/pdum/criu/goblins/__init__.py
344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 | |
utils
Helpers for locating CRIU-related executables on the system.
check_sudo_closefrom()
Probe sudo for closefrom_override support without raising.
Source code in src/pdum/criu/utils.py
368 369 370 371 372 373 374 375 376 377 | |
doctor_check_results(verbose=True)
Run the same checks as the CLI doctor command.
Returns a list of (label, ok, message) tuples.
Source code in src/pdum/criu/utils.py
380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 | |
ensure_criu(*, verbose=True, raise_=False, **kwargs)
Ensure the criu executable is available.
Source code in src/pdum/criu/utils.py
142 143 144 145 146 147 148 149 150 151 | |
ensure_criu_ns(*, verbose=True, raise_=False, **kwargs)
Ensure the criu-ns helper is available.
Source code in src/pdum/criu/utils.py
154 155 156 157 158 159 160 161 162 163 | |
ensure_linux()
Raise if the current platform is not Linux.
Source code in src/pdum/criu/utils.py
264 265 266 267 268 | |
ensure_pgrep(*, verbose=True, raise_=False, **kwargs)
Ensure the pgrep utility is available.
Source code in src/pdum/criu/utils.py
166 167 168 169 170 171 172 173 174 175 | |
ensure_sudo(*, verbose=True, raise_=False, **kwargs)
Ensure sudo -n true succeeds on the current system.
Returns:
| Type | Description |
|---|---|
bool
|
True if the non-interactive sudo command exits with status 0, otherwise False. |
Source code in src/pdum/criu/utils.py
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 | |
ensure_sudo_closefrom()
Verify that sudo supports the -C flag (closefrom_override).
Source code in src/pdum/criu/utils.py
339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 | |
psgrep(query, *, ensure_unique=True)
Locate processes matching the supplied query using pgrep -f.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
query
|
str
|
Pattern passed to |
required |
ensure_unique
|
bool
|
When True, ensure exactly one PID is returned; otherwise, return all matches. |
True
|
Returns:
| Type | Description |
|---|---|
int | list[int]
|
PID of the unique match, or a list of PIDs when |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
RuntimeError
|
If no processes match, multiple matches are found while |
Source code in src/pdum/criu/utils.py
178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 | |
resolve_command(executable)
Resolve a supported command to a concrete executable path.
The resolver first checks PDUM_CRIU_<EXE> for an override (where <EXE>
is the capitalized executable name with non-alphanumerics replaced by
underscores) before falling back to shutil.which.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
executable
|
str
|
Default executable name to locate. Can be overridden via environment. |
required |
Returns:
| Type | Description |
|---|---|
str
|
Absolute path to the resolved executable. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
FileNotFoundError
|
If the executable cannot be located. |
Source code in src/pdum/criu/utils.py
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 | |
resolve_target_pid(pid, pattern)
Resolve a target PID either directly or via pgrep.
Source code in src/pdum/criu/utils.py
271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 | |
spawn_directory_cleanup(path, watched_pid)
Spawn a background helper that removes path when watched_pid exits.
Source code in src/pdum/criu/utils.py
302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 | |
tail_file(path, lines=10)
Return the last lines lines from path.
Source code in src/pdum/criu/utils.py
289 290 291 292 293 294 295 296 297 298 299 | |