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

徐州制作网站软件/网推技巧

徐州制作网站软件,网推技巧,服务网站建设排行,wordpress免费主题网站在Linux中,trap命令主要用于接收信号并采取行动,信号是异步发送到一个程序的事件,在默认情况下,可以终止一个程序,trap命令原型如下: trap command signal signal是指接收到的信号,command是接…

     在Linux中,trap命令主要用于接收信号并采取行动,信号是异步发送到一个程序的事件,在默认情况下,可以终止一个程序,trap命令原型如下:

trap command signal

signal是指接收到的信号,command是接收到该信号采取的行动。如下为两种简单的信号。

信号

说明

INT(2)

Ctrl + C

QUIT(3)

Ctrl + \

trap命令常见的用途在于脚本程序中断时完成清理工作,比如临时文件等。例子程序如下:

#!/bin/sh

trap 'rm -f /tmp/my_tmp_file_$$' INT

echo "creating file /tmp/my_tmp_file_$$"

date > /tmp/my_tmp_file_$$

echo "press interrupt (CTRL-C) to interrupt ......"

while [ -f /tmp/my_tmp_file_$$ ]; do

       echo "File exists"

       sleep 3

done

echo" we never get here"

exit 0

注:$$表示当前的shell进程号。运行该脚本,首先在tmp下创建临时文件my_tmp_file_$$,如果遇到INT中断,即Ctrl+c,即删除该文件。

    trap [-lp] [[arg] sigspec ...]

 

格式:trap "commands" signals

当shell接收到signals指定的信号时,执行commands命令。(The  command arg is to be read and executed when the shell receives signal(s) sigspec. )

 

格式:trap signals

如果没有指定命令部分,那么就将信号处理复原。比如 trap INT 就表明恢复Ctrl+C退出。(If arg is absent (and there is a single sigspec) or -, each specified signal is reset to its  original  disposition  (the value  it  had  upon  entrance  to  the  shell). )

 

格式:trap "" signals

忽略信号signals,可以多个,比如 trap "" INT 表明忽略SIGINT信号,按Ctrl+C也不能使脚本退出。又如 trap "" HUP 表明忽略SIGHUP信号,即网络断开时也不能使脚本退出。(If arg is the null string the signal specified by each sigspec is ignored by the shell and by the commands it invokes. )

 

格式:trap -p

格式:trap -p signal

把当前的trap设置打印出来。(If arg is not present and -p  has  been supplied,  then  the trap commands associated with each sigspec are displayed.  If no arguments are supplied or if only -p is given, trap prints the list of commands associated  with  each  signal.)

 

格式:trap -l

把所有信号打印出来。(The  -l option  causes  the shell to print a list of signal names and their corresponding numbers.  Each sigspec is either a signal name defined in <signal.h>, or a signal number.  Signal names  are  case  insensitive and  the  SIG prefix is optional.) 

 

格式:trap "commands" EXIT

脚本退出时执行commands指定的命令。(If a sigspec is EXIT (0) the command arg is executed on exit from the shell.)

 

格式:trap "commands" DEBUG

在脚本执行时打印调试信息,比如打印将要执行的命令及参数列表。(If a sigspec is DEBUG, the command arg is executed before every  simple  command,  for  command, case  command,  select command, every arithmetic for command, and before the first command executes in a shell function (see SHELL GRAMMAR above).  Refer to the description of the extdebug option to the  shopt builtin  for  details of its effect on the DEBUG trap.)

 

格式:trap "commands" ERR

当命令出错,退出码非0,执行commands指定的命令。(If a sigspec is ERR, the command arg is executed whenever a simple command has a non-zero exit status, subject to the following conditions.  The ERR trap is not executed if the failed command is part of the command list immediately following a while or until keyword, part of the test in an if statement, part of a && or ┅Ι│ list, or if the command’s return  value is  being  inverted via !.  These are the same conditions obeyed by the errexit option.)

 

格式:trap "commands" RETURN

当从shell函数返回、或者使用source命令执行另一个脚本文件时,执行commands指定的命令。(If a sigspec is RETURN, the command arg is executed each time a shell function or a script executed with the . or source    builtins  finishes  executing.   Signals  ignored  upon  entry  to the shell cannot be trapped or reset. Trapped signals that are not being ignored are reset to their original values in a child process when it is created.  The return status is false if any sigspec is invalid; otherwise trap returns true.)



http://www.jmfq.cn/news/5122567.html

相关文章:

  • wordpress做商城网站/关键词诊断优化全部关键词
  • 潍坊网站建设推广报价/年度关键词有哪些
  • 用ps如何做模板下载网站/深圳推广网络
  • 杭州做网站优化/杭州seo技术培训
  • 品牌建设是指什么的行为过程/seo优化方案案例
  • 云梦模板网站优缺点/中国培训网的证书含金量
  • 邵阳网站网站建设/天天广告联盟
  • 青岛代理记账公司现状/官网排名优化
  • 网站维护多少钱/论坛推广工具
  • 网站开发案例/网络营销策划创意案例点评
  • 网站建设中图片/平台营销
  • 网站开发价格 北京/旅游网站网页设计
  • 网站建设改版攻略/软文推广例子
  • php政府网站模板/百度竞价排名机制
  • 事业单位网站建设计划/网站关键词优化价格
  • 那些网站可以做宣传/东莞百度推广排名
  • 青岛网站设计哪家便宜/抖音广告怎么投放
  • 想给公司做个网站怎么做/简述网站推广的意义和方法
  • 旧域名怎么做新网站/百度一下你就知道下
  • 如何建立免费网站的步骤/宁波seo外包方案
  • 重庆公司做网站/百度网页版网址
  • 用asp做网站需要准备什么软件/hao123网址大全浏览器设为主页
  • 中国洛阳网/南昌seo
  • 怎么用网站源码做网站/bt兔子磁力天堂
  • 商会网站建设方案/营销型网站建站推广
  • 建立一个商城网站/产品软文范例大全
  • 网站主页图片怎么换/惠州seo排名收费
  • 做游戏解说上传在什么网站好/个人怎么建立网站
  • 手表网站哪家好/安卓优化大师老版本
  • 网站开发都有/网站建站公司