当前位置: 首页 > news >正文

免费建设旅游网站优化课程

免费建设旅游网站,优化课程,wordpress木子,零基础学做网站trap 命令用于指定在接收到信号后将要采取的动作,常见的用途是在脚本程序被中断时完成清理工作。当 shell 接收到 sigspec 指定的信号时, arg 参数(通常是执行命令)会被读取,并被执行。 1. 命令介绍 开始掌握基本的使用方式和方法 [1] 语法…

trap 命令用于指定在接收到信号后将要采取的动作,常见的用途是在脚本程序被中断时完成清理工作。当 shell 接收到 sigspec 指定的信号时, arg 参数(通常是执行命令)会被读取,并被执行。

在这里插入图片描述

1. 命令介绍

开始掌握基本的使用方式和方法

[1] 语法格式

trap [-lp] [[arg] sigspec …]
[2] 参数选项

编号 参数 含义
1 -p 列出当前设置的 trap 方法
2 -l 列出信号名称和相应的数字
[3] 常用的信号量

Number Name Notes
0 EXIT Always run on shell exit, regardless of exit code
1 SIGHUP -
2 SIGINT This is what ^C sends
3 SIGQUIT -
6 SIGABRT -
9 SIGKILL -
14 SIGALRM -
15 SIGTERM This is what kill sends by default

2. 实例说明

纸上得来终觉浅,绝知此事要躬行。

[1] 累计在退出时运行的trap工作列表

#on_exit and add_on_exit
#Usage:
#add_on_exit rm -f /tmp/foo
#add_on_exit echo “I am exiting”
#tempfile=KaTeX parse error: Expected 'EOF', got '#' at position 10: (mktemp) #̲add_on_exit rm …tempfile"

function on_exit() {
for i in “${on_exit_items[@]}”; do
eval $i
done
}

function add_on_exit() {
local n=KaTeX parse error: Expected '}', got '#' at position 2: {#̲on_exit_items[*…n]=“$*”
if [[ $n -eq 0 ]]; then
trap on_exit EXIT
fi
}

add_on_exit echo “I am exiting”
[2] 捕获SIGINT或Ctrl+C
#Run a command on signal 2 (SIGINT, which is what ^C sends)
function sigint() {
echo “Killed subshell!”
}

trap sigint INT

#This will be killed on the first ^C
echo “Sleeping…”
sleep 500
echo “Sleeping…”
sleep 500

#pressing ^C twice in a second to quit
last=0
function allow_quit() {
[ $(date +%s) -lt $(( KaTeX parse error: Expected 'EOF', got '&' at position 15: last + 1 )) ] &̲& exit echo…(date +%s)
}

trap allow_quit INT
[3] 清理临时文件
#Make a cleanup function
function cleanup() {
rm --force – “${tmp}”
}

#Trap special “EXIT” group, which is always run when the shell exits.
trap cleanup EXIT

#Create a temporary file
tmp=“(mktemp−p/tmptmpfileXXXXXXX)"echo"Hello,world!">>"(mktemp -p /tmp tmpfileXXXXXXX)" echo "Hello, world!" >> "(mktempp/tmptmpfileXXXXXXX)"echo"Hello,world!">>"{tmp}”
[4] 在退出时杀死子进程
#kill all spawned child processes of the shell on exit
trap ‘jobs -p | xargs kill’ EXIT
[5] 对终端窗口大小的变化做出反应
#signal WINCH(WINdowCHange) that is fired when one resizes a terminal window
declare -x rows cols

function update_size(){
rows=KaTeX parse error: Expected 'EOF', got '#' at position 14: (tput lines) #̲ get actual lin…(tput cols) # get actual columns of term
echo DEBUG terminal window has no $rows lines and is $cols characters wide
}

trap update_size WINCH

3. 删除进程树

一条命令也可以完成一个脚本的工作量

#How to get PID,PGID,sessionid etc ?
$ ps -o pid,ppid,pgid,gid,sess,cmd -U root
PID PPID PGID GID SESS CMD

#1.kill a group of processes with negative PID(Process ID)
$ kill -TERM -PID

#2. kill a group of processes with their PGID(Process Group ID)
$ kill – -$PGID Kill using the default signal (TERM = 15)
$ kill -9 -$PGID Kill using the KILL signal (9)

#3. kill a group processes with only PID info
$ kill – -$(ps -o pgid= $PID | grep -o [0-9]*)

#4.Using pkill, kill processes by PGID(Proess Group ID)
$ pkill -9 -g $PGID

#5.Using pkill, kill processes by GID(Group ID)
$ pkill -9 -G $GID

#6.Using pkill, kill processes by PPID(Parent Process ID)
$ pkill -9 -p $PPID

#7.Using pkill, kill processes by terminal
$ pkill -9 -t $terminal

#8.Using pkill, kill processes by process name
$ pkill -9 -x $process_name

#9.Using pkill, kill processes by session
$ pkill -9 -s $sess
新的一年
新的征程
新的课程开班
等你来学!

http://www.jinmujx.cn/news/117772.html

相关文章:

  • 做淘宝类网站app拉新佣金排行榜
  • jsp做购物网站技术可行性上海百度推广优化
  • 收录网站工具合肥网站推广公司哪家好
  • 网站的ico图标做多大seo的主要工作是什么
  • 独立站官网搜索引擎营销的内容和层次有哪些
  • 阿里云个人备案可以做企业网站吗百度推广和优化哪个好
  • 工程承包合同范本免费百度如何优化排名靠前
  • 求个网站或者appseo关键词排名优化软件
  • 重庆市建设节能中心网站seo搜索引擎优化推广
  • 大同网站建设哪里好谷歌是如何运营的
  • 游戏网站设计论文seo的工作内容主要包括
  • 自动的网站制作班级优化大师客服电话
  • 怎么把网站管理系统百度sem竞价托管
  • 政府网站建设团队百度搜索排名怎么靠前
  • 如何做网站标题不含关键词的排名网站流量指标有哪些
  • 什么网站容易收录谈谈你对seo概念的理解
  • wordpress mysql用户名搜索引擎的优化和推广
  • 做企业网站价格韶山百度seo
  • 商城网站开发文档2021百度最新收录方法
  • 淘宝客做软件网站app搜狗推广登录平台
  • 做微信小程序合肥seo网站排名
  • 如何用织梦建网站信息如何优化上百度首页
  • 为什么做网站必须用服务器网络营销课程个人总结范文
  • 怎么做网络直播卖衣服的网站方象科技的企业愿景
  • 做新闻h5网站怎样做网站卖自己的产品
  • 网站怎么挂广告网站数据分析
  • 去哪里找空间做网站俄罗斯搜索引擎推广
  • 博客网站需要的功能小红书seo优化
  • 做视频网站视频加载过慢推广软文范例
  • ps做网站ui手机网站建设