一文弄懂arm linux信号的分类及其作用

0

4

信号

信号可工作在单个进程和多个进程中,用于处理异步事件。

主要包含两个 :alarm (用于产生闹钟信号)及signal (处理各类信号,包括但不限闹钟信号)

alarm:闹钟,参数是时间,成功返回0或剩余时间,错误返回-1

usigned int alarm(unsigned int seconds);

signal:参数signum为等待的信号,handler为触发处理方式,类似中断处理函数,成功返回0,错误返回-1

sighandler_t signal(int signum,sighandler_t handler);

等待信号的类型定义文件:其中包含有各类信号,包括闹钟信号SIGALRM、空闲信号SIGHUP、退出信号SIGQUIT等等,因此结合各类信号可实现不同功能的异步调用。

/* Signal number constants. Generic template.

Copyright (C) 1991-2020 Free Software Foundation, Inc.

This file is part of the GNU C Library.

The GNU C Library is free software; you can redistribute it and/or

modify it under the terms of the GNU Lesser General Public

License as published by the Free Software Foundation; either

version 2.1 of the License, or (at your option) any later version.

The GNU C Library is distributed in the hope that it will be useful,

but WITHOUT ANY WARRANTY; without even the implied warranty of

MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU

Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public

License along with the GNU C Library; if not, see

#ifndef _BITS_SIGNUM_GENERIC_H

#define _BITS_SIGNUM_GENERIC_H 1

#ifndef _SIGNAL_H

#error "Never include directly; use instead."

#endif

#define SIG_ERR ((__sighandler_t) -1) /* Error return. */

#define SIG_DFL ((__sighandler_t) 0) /* Default action. */

#define SIG_IGN ((__sighandler_t) 1) /* Ignore signal. */

#ifdef __USE_XOPEN

# define SIG_HOLD ((__sighandler_t) 2) /* Add signal to hold mask. */

#endif

#define SIGINT 2 /* Interactive attention signal. */

#define SIGILL 4 /* Illegal instruction. */

#define SIGABRT 6 /* Abnormal termination. */

#define SIGFPE 8 /* Erroneous arithmetic operation. */

#define SIGSEGV 11 /* Invalid access to storage. */

#define SIGTERM 15 /* Termination request. */

#define SIGHUP 1 /* Hangup. */

#define SIGQUIT 3 /* Quit. */

#define SIGTRAP 5 /* Trace/breakpoint trap. */

#define SIGKILL 9 /* Killed. */

#define SIGBUS 10 /* Bus error. */

#define SIGSYS 12 /* Bad system call. */

#define SIGPIPE 13 /* Broken pipe. */

#define SIGALRM 14 /* Alarm clock. */

#define SIGURG 16 /* Urgent data is available at a socket. */

#define SIGSTOP 17 /* Stop, unblockable. */

#define SIGTSTP 18 /* Keyboard stop. */

#define SIGCONT 19 /* Continue. */

#define SIGCHLD 20 /* Child terminated or stopped. */

#define SIGTTIN 21 /* Background read from control terminal. */

#define SIGTTOU 22 /* Background write to control terminal. */

#define SIGPOLL 23 /* Pollable event occurred (System V). */

#define SIGXCPU 24 /* CPU time limit exceeded. */

#define SIGXFSZ 25 /* File size limit exceeded. */

#define SIGVTALRM 26 /* Virtual timer expired. */

#define SIGPROF 27 /* Profiling timer expired. */

#define SIGUSR1 30 /* User-defined signal 1. */

#define SIGUSR2 31 /* User-defined signal 2. */

#define SIGWINCH 28 /* Window size change (4.3 BSD, Sun). */

#define SIGIO SIGPOLL /* I/O now possible (4.2 BSD). */

#define SIGIOT SIGABRT /* IOT instruction, abort() on a PDP-11. */

#define SIGCLD SIGCHLD /* Old System V name */

#define __SIGRTMIN 32

#define __SIGRTMAX __SIGRTMIN

#define _NSIG (__SIGRTMAX + 1)

#endif /* bits/signum-generic.h. */

编写测试程序:

#include

#include

#include

void sig_handler()

{

printf("hello handler

");

}

int main (void)

{

signal(SIGALRM,sig_handler);

alarm(5);

for (int i = 0; i < 7; i++)

{

printf("sleep_....%d seconds

",i);

sleep(1);

}

}

如果linux内核和开发板一样的话可以直接在ubuntu上测试:

root@ubuntu:/home/wly/topeet/code_for_linux_application# ./signal

sleep_....0 seconds

sleep_....1 seconds

sleep_....2 seconds

sleep_....3 seconds

sleep_....4 seconds

hello handler

sleep_....5 seconds

sleep_....6 seconds

root@ubuntu:/home/wly/topeet/code_for_linux_application#

原作者:T触发器

只看该作者

淘帖0

举报

相关推荐

• 一文弄懂LDO

89

• 一文弄懂人员定位系统的功能和作用

1999

• 一文弄懂Linux硬链接和软链接

1661

• 一文弄懂电阻器在电路当中的作用

11103

• 一文弄懂ARM芯片的地址重映射

4206

• 一文弄懂电流互感器的原理及作用

37354

• 一文弄懂矩阵键盘是什么

1631

• 一文弄懂IGBT驱动

2779

• 一文弄懂CPU卡是什么

43852

• 一文弄懂仪表安装

10172

评论

B

Color

Link

Quote

Code

Smilies

您需要登录后才可以回帖 登录/注册

发布

声明:本文内容及配图由入驻作者撰写或者入驻合作网站授权转载。文章观点仅代表作者本人,不代表电子发烧友网立场。文章及其配图仅供工程师学习之用,如有内容图片侵权或者其他问题,请联系本站作侵删。 侵权投诉

发经验

精选推荐

飞凌嵌入式ElfBoard-目录权限之chmod

481 浏览

0 评论

飞凌嵌入式ElfBoard-获取文件的状态信息之文件权限

692 浏览

0 评论

Linux系统冗余设计裁剪开机时间优化

425 浏览

0 评论

飞凌嵌入式ElfBoard-获取文件的状态信息之文件权限

522 浏览

0 评论

Comake Pi D2开箱测评

1820 浏览

0 评论

快速回复

返回顶部

返回列表

关注微信公众号

电子发烧友网

电子发烧友论坛

社区合作

刘勇

联系电话:15994832713

邮箱地址:liuyong@huaqiu.com

社区管理

elecfans短短

微信:elecfans_666

邮箱:users@huaqiu.com