更新升级 专属应用 系统故障 硬件故障 电脑汽车 鸿蒙刷机 鸿蒙开发Linux教程 鸿蒙开发Linux命令
当前位置:HMXT之家 > 鸿蒙开发Linux命令 > Linux pssh、pushd、pstree、pstack命令的用法及解释

Linux pssh、pushd、pstree、pstack命令的用法及解释

更新时间:2022-01-20 11:26:10浏览次数:800+次

以下为你详细解释pssh、pushd、pstree、pstack命令的用法。

\

Linux pssh命令的用法及解释

Linux pssh命令是一个python编写可以在多台服务器上执行命令的工具,同时支持拷贝文件,是同类工具中很出色的,类似pdsh,个人认为相对pdsh更为简便,使用必须在各个服务器上配置好密钥认证访问。

1、安装pssh

在CentOS系统环境下,介绍yum的安装和源码安装的方式:

yum方法:

yum install pssh

编译安装:

wget http://www.theether.org/pssh/pssh-1.4.3.tar.gz

tar xf pssh-1.4.3.tar.gz

cd pssh-1.4.3/

python setup.py install

2、选项

--version:查看版本

--help:查看帮助,即此信息

-h:主机文件列表,内容格式”[user@]host[:port]”

-H:主机字符串,内容格式”[user@]host[:port]”

-:登录使用的用户名

-p:并发的线程数【可选】

-o:输出的文件目录【可选】

-e:错误输入文件【可选】

-t:TIMEOUT 超时时间设置,0无限制【可选】

-O:SSH的选项

-v:详细模式

-A:手动输入密码模式

-x:额外的命令行参数使用空白符号,引号,反斜线处理

-X:额外的命令行参数,单个参数模式,同-x

-i:每个服务器内部处理信息输出

-P:打印出服务器返回信息

3、实例

获取每台服务器的uptime:

# pssh -h ip.txt -i uptime

[1] 11:15:03 [SUCCESS] Mar.mars.he

11:15:11 up 4 days, 16:25,  1 user,  load average: 0.00, 0.00, 0.00

[2] 11:15:03 [SUCCESS] Jan.mars.he

11:15:12 up 3 days, 23:26,  0 users,  load average: 0.00, 0.00, 0.00

[3] 11:15:03 [SUCCESS] Feb.mars.he

11:15:12 up 4 days, 16:26,  2 users,  load average: 0.08, 0.02, 0.01

查看每台服务器上mysql复制IO/SQL线程运行状态信息:

# pssh -h IP.txt -i "/usr/local/mysql/bin/mysql -e 'show slave status \G'"|grep Running:

Slave_IO_Running: yes

Slave_SQL_Running: Yes

Slave_IO_Running: Yes

Slave_SQL_Running: Yes

Slave_IO_Running: Yes

Slave_SQL_Running: Yes

保存每台服务器运行的结果:

# pssh -h IP.txt -i -o /tmp/pssh/ uptime

[1] 11:19:47 [SUCCESS] Feb.mars.he

11:19:55 up 4 days, 16:31,  2 users,  load average: 0.02, 0.03, 0.00

[2] 11:19:47 [SUCCESS] Jan.mars.he

11:19:56 up 3 days, 23:30,  0 users,  load average: 0.01, 0.00, 0.00

[3] 11:19:47 [SUCCESS] Mar.mars.he

11:19:56 up 4 days, 16:30,  1 user,  load average: 0.00, 0.00, 0.00

我们来看一下/tmp/pssh/下的文件及其内容:

# ll /tmp/pssh/

总用量 12

-rw-r--r--. 1 root root 70 12月  1 11:19 Feb.mars.he

-rw-r--r--. 1 root root 70 12月  1 11:19 Jan.mars.he

-rw-r--r--. 1 root root 69 12月  1 11:19 Mar.mars.he

# cat /tmp/pssh/*

11:19:55 up 4 days, 16:31,  2 users,  load average: 0.02, 0.03, 0.00

11:19:56 up 3 days, 23:30,  0 users,  load average: 0.01, 0.00, 0.00

11:19:56 up 4 days, 16:30,  1 user,  load average: 0.00, 0.00, 0.00

上面介绍的是pssh命令很少的一部分,大家可以将其用到适合自己的场景,发挥它的最大功效。

Linux pushd命令的用法及解释

Linux pushd命令是将目录加入命令堆叠中。如果指令没有指定目录名称,则会将当前的工作目录置入目录堆叠的最顶端。置入目录如果没有指定堆叠的位置,也会置入目录堆叠的最顶端,同时工作目录会自动切换到目录堆叠最顶端的目录去。

1、语法

pushd(选项)(参数)

2、选项

-n:只加入目录到堆叠中,不进行cd操作;

+n:删除从左到右的第n个目录,数字从0开始;

-n:删除从右到左的第n个目录,数字从0开始;

3、参数

目录:需要压入堆栈的目录。

4、实例

root@Mylinux:/tmp/dir4# pushd /tmp/dir3

/tmp/dir3 /tmp/dir4 /tmp/dir1 ~

root@Mylinux:/tmp/dir3# pushd /tmp/dir2

/tmp/dir2 /tmp/dir3 /tmp/dir4 /tmp/dir1 ~

root@Mylinux:/tmp/dir2# pushd -1

/tmp/dir1 ~ /tmp/dir2 /tmp/dir3 /tmp/dir4

注意:最左边表示栈顶,最右边表示栈底。

Linux pstree命令的用法及解释

Linux pstree命令以树状图的方式展现进程之间的派生关系,显示效果比较直观。

1、语法

pstree(选项)

2、选项

-a:显示每个程序的完整指令,包含路径,参数或是常驻服务的标示;

-c:不使用精简标示法;

-G:使用VT100终端机的列绘图字符;

-h:列出树状图时,特别标明现在执行的程序;

-H<程序识别码>:此参数的效果和指定"-h"参数类似,但特别标明指定的程序;

-l:采用长列格式显示树状图;

-n:用程序识别码排序。预设是以程序名称来排序;

-p:显示程序识别码;

-u:显示用户名称;

-U:使用UTF-8列绘图字符;

-V:显示版本信息。

3、实例

显示当前所有进程的进程号和进程id:

pstree -p

显示所有进程的所有详细信息,遇到相同的进程名可以压缩显示:

pstree  -a

Linux pstack命令的用法及解释

Linux pstack命令可显示每个进程的栈跟踪。pstack 命令必须由相应进程的属主或 root 运行。可以使用 pstack 来确定进程挂起的位置。此命令允许使用的唯一选项是要检查的进程的 PID。

命令软件包下载地址:https://packages.debian.org/sid/pstack

以下是实例:

1、pstree以树结构显示进程

pstree -p work | grep ad

sshd(22669)---bash(22670)---ad_preprocess(4551)-+-{ad_preprocess}(4552)

|-{ad_preprocess}(4553)

|-{ad_preprocess}(4554)

|-{ad_preprocess}(4555)

|-{ad_preprocess}(4556)

`-{ad_preprocess}(4557)

work为工作用户,-p为显示进程识别码,ad_preprocess共启动了6个子线程,加上主线程共7个线程。

ps -Lf 4551

\

2、进程共启动了7个线程

pstack显示每个进程的栈跟踪:

pstack 4551

Thread 7 (Thread 1084229984 (LWP 4552)):

#0  0x000000302afc63dc in epoll_wait () from /lib64/tls/libc.so.6

#1  0x00000000006f0730 in ub::EPollEx::poll ()

#2  0x00000000006f172a in ub::NetReactor::callback ()

#3  0x00000000006fbbbb in ub::UBTask::CALLBACK ()

#4  0x000000302b80610a in start_thread () from /lib64/tls/libpthread.so.0

#5  0x000000302afc6003 in clone () from /lib64/tls/libc.so.6

#6  0x0000000000000000 in ?? ()

Thread 6 (Thread 1094719840 (LWP 4553)):

#0  0x000000302afc63dc in epoll_wait () from /lib64/tls/libc.so.6

#1  0x00000000006f0730 in ub::EPollEx::poll ()

#2  0x00000000006f172a in ub::NetReactor::callback ()

#3  0x00000000006fbbbb in ub::UBTask::CALLBACK ()

#4  0x000000302b80610a in start_thread () from /lib64/tls/libpthread.so.0

#5  0x000000302afc6003 in clone () from /lib64/tls/libc.so.6

#6  0x0000000000000000 in ?? ()

Thread 5 (Thread 1105209696 (LWP 4554)):

#0  0x000000302b80baa5 in __nanosleep_nocancel ()

#1  0x000000000079e758 in comcm::ms_sleep ()

#2  0x00000000006c8581 in ub::UbClientManager::healthyCheck ()

#3  0x00000000006c8471 in ub::UbClientManager::start_healthy_check ()

#4  0x000000302b80610a in start_thread () from /lib64/tls/libpthread.so.0

#5  0x000000302afc6003 in clone () from /lib64/tls/libc.so.6

#6  0x0000000000000000 in ?? ()

Thread 4 (Thread 1115699552 (LWP 4555)):

#0  0x000000302b80baa5 in __nanosleep_nocancel ()

#1  0x0000000000482b0e in armor::armor_check_thread ()

#2  0x000000302b80610a in start_thread () from /lib64/tls/libpthread.so.0

#3  0x000000302afc6003 in clone () from /lib64/tls/libc.so.6

#4  0x0000000000000000 in ?? ()

Thread 3 (Thread 1126189408 (LWP 4556)):

#0  0x000000302af8f1a5 in __nanosleep_nocancel () from /lib64/tls/libc.so.6

#1  0x000000302af8f010 in sleep () from /lib64/tls/libc.so.6

#2  0x000000000044c972 in Business_config_manager::run ()

#3  0x0000000000457b83 in Thread::run_thread ()

#4  0x000000302b80610a in start_thread () from /lib64/tls/libpthread.so.0

#5  0x000000302afc6003 in clone () from /lib64/tls/libc.so.6

#6  0x0000000000000000 in ?? ()

Thread 2 (Thread 1136679264 (LWP 4557)):

#0  0x000000302af8f1a5 in __nanosleep_nocancel () from /lib64/tls/libc.so.6

#1  0x000000302af8f010 in sleep () from /lib64/tls/libc.so.6

#2  0x00000000004524bb in Process_thread::sleep_period ()

#3  0x0000000000452641 in Process_thread::run ()

#4  0x0000000000457b83 in Thread::run_thread ()

#5  0x000000302b80610a in start_thread () from /lib64/tls/libpthread.so.0

#6  0x000000302afc6003 in clone () from /lib64/tls/libc.so.6

#7  0x0000000000000000 in ?? ()

Thread 1 (Thread 182894129792 (LWP 4551)):

#0  0x000000302af8f1a5 in __nanosleep_nocancel () from /lib64/tls/libc.so.6

#1  0x000000302af8f010 in sleep () from /lib64/tls/libc.so.6

#2  0x0000000000420d79 in Ad_preprocess::run ()

#3  0x0000000000450ad0 in main ()