美文网首页
Linux trap

Linux trap

作者: 混沌中的菜菜 | 来源:发表于2016-06-08 18:21 被阅读35次

    trap是一个shell内建命令,它用来在脚本中指定信号如何处理。比如,按Ctrl+C会使脚本终止执行,实际上系统发送了SIGINT信号给脚本进程,SIGINT信号的默认处理方式就是退出程序。如果要在Ctrl+C不退出程序,那么就得使用trap命令来指定一下SIGINT的处理方式了。trap命令不仅仅处理Linux信号,还能对脚本退出(EXIT)、调试(DEBUG)、错误(ERR)、返回(RETURN)等情况指定处理方式。

    常用参数

       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. )

    相关文章

      网友评论

          本文标题:Linux trap

          本文链接:https://www.haomeiwen.com/subject/sapjdttx.html