chpst
TLDR
Run command as different user
SYNOPSIS
chpst [options] command
DESCRIPTION
chpst (change process state) runs a command with modified process attributes. It is part of the runit service supervision suite and provides a standardized way to set user, limits, and environment for service processes.
The tool consolidates several common process modifications: changing user/group identity, setting resource limits, loading environment from files, and obtaining locks. This simplifies service run scripts that would otherwise need multiple commands.
Environment directories (used with -e) contain files named for environment variables, with file contents as values. This pattern is common in runit and daemontools service management.
PARAMETERS
-u user[:group]
Set UID and GID before running command.-e directory
Set environment variables from files in directory.-m bytes
Limit data segment, stack, and locked memory.-d bytes
Limit data segment size.-o n
Limit number of open file descriptors.-p n
Limit number of processes.-f bytes
Limit output file size.-c bytes
Limit core dump size.-n inc
Adjust nice level.-/ dir
Change root directory (chroot).-l lock
Create exclusive lock file.-L lock
Wait for exclusive lock file.-v
Verbose output.
CAVEATS
Changing user requires root privileges. Resource limits are per-process; child processes inherit but have their own limits. The chroot option requires a complete root filesystem at the target. Lock files must be on a filesystem supporting locks.
HISTORY
chpst was created by Gerrit Pape as part of runit, a Unix init scheme with service supervision, released in the early 2000s. It was inspired by similar tools from daemontools (setuidgid, softlimit, envdir) but combines their functionality into a single command. The tool remains popular for its simplicity and is used beyond runit in various service management contexts.


