Linux command
chpst 命令
文本
复制后可按需替换文件名、目录或参数。
常用示例
Run command as different user
chpst -u [user] [command]
Run with specific user and group
chpst -u [user:group] [command]
Limit memory usage
chpst -m [50000000] [command]
Set environment from directory
chpst -e [/etc/service/myapp/env] [command]
Change to directory before running
chpst -/ [/var/lib/app] [command]
Limit number of open files
chpst -o [1000] [command]
Set nice level
chpst -n [10] [command]
说明
chpst changes the process state according to the given options and runs prog. 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.
参数
- -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).
- -C _pwd_
- Change working directory to pwd before starting prog. Combined with -/, the directory is changed after chroot.
- -b _argv0_
- Run prog with argv0 as its 0th argument.
- -l _lock_
- Open lock for writing, obtain an exclusive lock, and fail immediately if lock is held by another process.
- -L _lock_
- Open lock for writing, obtain an exclusive lock, and wait if lock is held by another process.
- -P
- Run prog in a new process group.
- -0, -1, -2
- Close standard input (0), standard output (1), or standard error (2) before starting prog.
- -v
- Print verbose messages to standard error.
FAQ
What is the chpst command used for?
chpst changes the process state according to the given options and runs prog. 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.
How do I run a basic chpst example?
Run `chpst -u [user] [command]` in a terminal, then adjust file names, paths, flags, or remote targets for your system.
What does -u _user:group_ do in chpst?
Set UID and GID before running command.