乐维
标题:
[Psmisc]分享一个Linux实用性命令工具
[打印本页]
作者:
乐维
时间:
2020-10-13 09:33
标题:
[Psmisc]分享一个Linux实用性命令工具
安装:
yum install
–
y psmisc
离线包安装下载链接
https://developer.aliyun.com/packageSearch?word=psmisc
(, 下载次数: 0)
上传
点击文件名下载附件
此工具
常用3个管理命令:
1、 pstree 以树状形式显示当前用户下正在运行的进程,用法:
Usage: pstree [ -a ] [ -c ] [ -h | -H PID ] [ -l ] [ -n ] [ -p ] [ -g ] [ -u ]
[ -A | -G | -U ] [ PID | USER ]
pstree -V
Display a tree of processes.
-a, --arguments show command line arguments
-A, --ascii use ASCII line drawing characters
-c, --compact don't compact identical subtrees
-h, --highlight-all highlight current process and its ancestors
-H PID,
--highlight-pid=PID highlight this process and its ancestors
-g, --show-pgids show process group ids; implies -c
-G, --vt100 use VT100 line drawing characters
-l, --long don't truncate long lines
-n, --numeric-sort sort output by PID
-N type,
--ns-sort=type sort by namespace type (ipc, mnt, net, pid, user, uts)
-p, --show-pids show PIDs; implies -c
-s, --show-parents show parents of the selected process
-S, --ns-changes show namespace transitions
-u, --uid-changes show uid transitions
-U, --unicode use UTF-8 (Unicode) line drawing characters
-V, --version display version information
-Z,
--security-context show SELinux security contexts
PID start at this PID; default is 1 (init)
USER show only trees rooted at processes of this user
例如使用
pstree
–
a
显示所有进程的子进程
(, 下载次数: 0)
上传
点击文件名下载附件
使用
pstree
–
p
显示所有进程及其子进程的
pid
(, 下载次数: 0)
上传
点击文件名下载附件
树状显示指定的主进程及其子进程
(, 下载次数: 0)
上传
点击文件名下载附件
2
、
fuser
用法:
Usage: fuser [-fMuvw] [-a|-s] [-4|-6] [-c|-m|-n SPACE] [-k [-i] [-SIGNAL]] NAME...
fuser -l
fuser -V
Show which processes use the named files, sockets, or filesystems.
-a,--all display unused files too
-i,--interactive ask before killing (ignored without -k)
-k,--kill kill processes accessing the named file
-l,--list-signals list available signal names
-m,--mount show all processes using the named filesystems or block device
-M,--ismountpoint fulfill request only if NAME is a mount point
-n,--namespace SPACE search in this name space (file, udp, or tcp)
-s,--silent silent operation
-SIGNAL send this signal instead of SIGKILL
-u,--user display user IDs
-v,--verbose verbose output
-w,--writeonly kill only processes with write access
-V,--version display version information
-4,--ipv4 search IPv4 sockets only
-6,--ipv6 search IPv6 sockets only
- reset options
udp/tcp names: [local_port][,[rmt_host][,[rmt_port]]]
举例:想停止某个进程但发现有很多子进程的情况下,可以通过停止主进程使用的端口,达到停止进程的目的。还有个情况就是如果重装某个软件,启动时候,提示已存在进程或者端口被占用,那么可以使用
fuser
–
k port/tcp
停止相关占用端口的进程,如
fuser
–
k 80/tcp
;
如通过杀掉
10050
端口停止
zabbix-server进程占用端口
fuser -k 10050/tcp
(, 下载次数: 0)
上传
点击文件名下载附件
可以发现
10050端口已经停止了!
(, 下载次数: 0)
上传
点击文件名下载附件
3
、
killal
l 命令,用法:
[root@zbx34 ~]# killall --help
Usage: killall [-Z CONTEXT] [-u USER] [ -eIgiqrvw ] [ -SIGNAL ] NAME...
killall -l, --list
killall -V, --version
-e,--exact require exact match for very long names
-I,--ignore-case case insensitive process name match
-g,--process-group kill process group instead of process
-y,--younger-than kill processes younger than TIME
-o,--older-than kill processes older than TIME
-i,--interactive ask for confirmation before killing
-l,--list list all known signal names
-q,--quiet don't print complaints
-r,--regexp interpret NAME as an extended regular expression
-s,--signal SIGNAL send this signal instead of SIGTERM
-u,--user USER kill only process(es) running as USER
-v,--verbose report if the signal was successfully sent
-V,--version display version information
-w,--wait wait for processes to die
-Z,--context REGEXP kill only process(es) having context
(must precede other arguments)
举例:杀掉
zabbix_server进程
(, 下载次数: 0)
上传
点击文件名下载附件
Psmisc
工具相对来比系统默认自带的命令会比较方便,停止进程不必一个一个的杀掉
pid,更多的功能大家可以自行拓展。
技术交流欢迎加入Q群:177428068
欢迎光临 乐维 (http://lwops.cn/)
Powered by Discuz! X3.4