当前位置: ManBetXapp > 百科 > 科技 >正文

linux swapoff命令详解

人气:189 ℃ /2022-12-27 07:54:21

Linux系统下swapoff命令用于关闭系统交换区(swap area),下面是swapoff命令内容的具体内容:

1、swapoff命令简介:

Linux系统下swapoff命令用于关闭系统交换区(swap area),swapoff实际上为swapon的符号连接,可用来关闭系统的交换区。

2、语法:

swapoff [设备]

3、参数:

-a将/etc/fstab文件中所有设置为swap的设备关闭 ;

-h帮助信息;

-V版本信息 。

实例:

显示分区信息,输入命令:

# sfdisk -l //显示分区信息

Disk /dev/sda: 1305 cylinders, 255 heads, 63 sectors/track

Units = cylinders of 8225280 bytes, blocks of 1024

以上就是小编今天的分享了,希望可以帮助到大家。

linux系统什么情况下使用swap

Linux下精确定位使用swap的进程,网友:值得拥有

相信做过运维的朋友,一定碰到在linux系统中,有时候会使用swap交换分区,一旦应用使用了swap,那么性能就会直线下降,应用响应时间变成,过一会儿,应用不再使用swap,应用又自动恢复了。

当运维人员去定位到底是哪个应用使用swap交换分区时,又非常的困难,因为很少有日志会记录这个,从监控平台,能看到某个时间段,linux的swap交换分区有使用。

为了解决这个问题,下面给大家分享一个Linux下精确定位使用swap的进程的shell脚本,这个脚本可以放到crontab下,一分钟执行一次。

脚本内容如下所示

[root@localhost ~]# cat swap.sh #!/bin/bash# Get current swap usage for all running processesfunction getswap {SUM=0OVERALL=0for DIR in `find /proc/ -maxdepth 1 -type d | egrep "^/proc/[0-9]"` ; doPID=`echo $DIR | cut -d / -f 3`PROGNAME=`ps -p $PID -o comm --no-headers`for SWAP in `grep Swap $DIR/smaps 2>/dev/null| awk '{ print $2 }'`dolet SUM=$SUM $SWAPdoneecho "PID=$PID - Swap used: $SUM - ($PROGNAME )"let OVERALL=$OVERALL $SUMSUM=0doneecho "Overall swap used: $OVERALL"}getswap输出结果[root@localhost ~]# ./swap.sh PID=1 - Swap used: 0 - (systemd )PID=2 - Swap used: 0 - (kthreadd )PID=4 - Swap used: 0 - (kworker/0:0H )PID=5 - Swap used: 0 - (kworker/u256:0 )PID=6 - Swap used: 0 - (ksoftirqd/0 )PID=7 - Swap used: 0 - (migration/0 )PID=8 - Swap used: 0 - (rcu_bh )PID=9 - Swap used: 0 - (rcu_sched )PID=10 - Swap used: 0 - (lru-add-drain )PID=11 - Swap used: 0 - (watchdog/0 )PID=13 - Swap used: 0 - (kdevtmpfs )PID=14 - Swap used: 0 - (netns )PID=15 - Swap used: 0 - (khungtaskd )PID=16 - Swap used: 0 - (writeback )PID=17 - Swap used: 0 - (kintegrityd )PID=18 - Swap used: 0 - (bioset )PID=19 - Swap used: 0 - (bioset )PID=20 - Swap used: 0 - (bioset )PID=21 - Swap used: 0 - (kblockd )PID=22 - Swap used: 0 - (md )PID=23 - Swap used: 0 - (edac-poller )Overall swap used: 0如果觉得输出的结果太多,还可以过滤掉Swap used: 0的记录

[root@localhost ~]# cat swap.sh #!/bin/bash# Get current swap usage for all running processesfunction getswap {SUM=0OVERALL=0for DIR in `find /proc/ -maxdepth 1 -type d | egrep "^/proc/[0-9]"` ; doPID=`echo $DIR | cut -d / -f 3`PROGNAME=`ps -p $PID -o comm --no-headers`for SWAP in `grep Swap $DIR/smaps 2>/dev/null| awk '{ print $2 }'`dolet SUM=$SUM $SWAPdoneecho "PID=$PID - Swap used: $SUM - ($PROGNAME )"let OVERALL=$OVERALL $SUMSUM=0doneecho "Overall swap used: $OVERALL"}getswap|egrep -v "Swap used: 0"输出结果[root@localhost ~]# ./swap.sh Overall swap used: 0

这个功能脚本,你值得收藏。

搜索更多有关“ linux swapoff命令详解”的信息 [百度搜索] [SoGou搜索] [头条搜索] [360搜索]
CopyRight © 2008-2024 ManBetXappAll Rights Reserved. 手机版