zoukankan      html  css  js  c++  java
  • 如何产生信号

    1、通过终端按键产生信号

         在前台进程输入ctrl+c或者ctrl+/可以产生硬件中断。

    2、调用系统函数向进程发信号

    在shell命令下发送信号具体格式如下

    $ ./a.out &
    [1] 7940
    $ kill -SIGSEGV 7940
    $(再次回车)
    [1]+  Segmentation fault      (core dumped) ./a.out

    7940是a.out进程的id。之所以要再次回车才显示Segmentation fault,是因为在7940进程终止掉之前已经回到了Shell提示符等待用户输入下一条命令,Shell不希望Segmentation fault信息和用户的输入交错在一起,所以等用户输入命令之后才显示。指定某种信号的kill命令可以有多种写法,上面的命令还可以写成kill -SEGV 7940kill -11 7940,11是信号SIGSEGV的编号。以往遇到的段错误都是由非法内存访问产生的,而这个程序本身没错,给它发SIGSEGV也能产生段错误。

    3、软件本身产生中断

    比如由alarm函数产生的SIGALRM信号。

    #include <unistd.h>
    #include <stdio.h>
    
    int main(void)
    {
        int counter;
        alarm(1);
        for(counter=0; 1; counter++)
            printf("counter=%d ", counter);
        return 0;
    }
  • 相关阅读:
    性能测试资源监控工具nmon使用方法
    Java用递归实现全排列,详细
    LaTeX新人使用教程[转载]
    计算机视觉论文分级
    如何用 tensorflow serving 部署服务
    Docker清除容器镜像命令:
    docker: Error response from daemon: invalid mount config for type "bind": bind source path does not exist: /tmp/tfserving/
    Invalid argument: Key: label. Data types don't match. Data type: int64 but expected type: float
    Could not install packages due to an EnvironmentError: [Errno 13] Permission denied: '/usr/local/bin/tensorboard'
    tensorflow.python.framework.errors_impl.PermissionDeniedError: /data; Permission denied
  • 原文地址:https://www.cnblogs.com/pang1567/p/3649863.html
Copyright © 2011-2022 走看看