⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sigint.html

📁 this is a mirrored site c-faq. thought might need offline
💻 HTML
字号:
<!DOCTYPE HTML PUBLIC "-//W3O//DTD W3 HTML 2.0//EN"><!-- This collection of hypertext pages is Copyright 1995-2005 by Steve Summit. --><!-- Content from the book "C Programming FAQs: Frequently Asked Questions" --><!-- (Addison-Wesley, 1995, ISBN 0-201-84519-9) is made available here by --><!-- permission of the author and the publisher as a service to the community. --><!-- It is intended to complement the use of the published text --><!-- and is protected by international copyright laws. --><!-- The on-line content may be accessed freely for personal use --><!-- but may not be published or retransmitted without explicit permission. --><!-- --><!-- this page built Sat Dec 24 21:47:47 2005 by faqproc version 2.7 --><!-- from source file osdepmisc.sgml dated Wed Dec 21 13:04:19 2005 --><!-- corresponding to FAQ list version 4.0 --><html><!-- Mirrored from c-faq.com/osdep/sigint.html by HTTrack Website Copier/3.x [XR&CO'2008], Sat, 14 Mar 2009 07:59:04 GMT --><head><meta name=GENERATOR content="faqproc"><title>Question 19.38</title><link href="subsecond.html" rev=precedes><link href="fpexcepts.html" rel=precedes><link href="index.html" rev=subdocument></head><body bgcolor="#ffffff"><a href="subsecond.html" rev=precedes><img src="../images/buttonleft.gif" alt="prev"></a><a href="index.html" rev=subdocument><img src="../images/buttonup.gif" alt="up"></a><a href="fpexcepts.html" rel=precedes><img src="../images/buttonright.gif" alt="next"></a>&nbsp;<a href="../index-2.html"><img src="../images/buttontop.gif" alt="top/contents"></a><a href="../search.html"><img src="../images/buttonsrch.gif" alt="search"></a><hr><p><!-- qbegin --><h1>comp.lang.c FAQ list<font color=blue>&middot;</font><!-- qtag -->Question 19.38</h1><p><font face=Helvetica size=8 color=blue><b>Q:</b></font>How can I trap or ignorekeyboard interruptslikecontrol-C?</p><p><hr><p><font face=Helvetica size=8 color=blue><b>A:</b></font>The basic step is to call <TT>signal</TT>,either as<pre>	#include &lt;signal.h&gt;	signal(SIGINT, SIG_IGN);</pre>to ignorethe interrupt signal,or as<pre>	extern void func(int);	signal(SIGINT, func);</pre>to cause control to transfer to function <TT>func</TT>on receipt ofan interrupt signal.<a href="keybintr.html" rel=subdocument>[footnote]</a></p><p>On a multi-tasking system such as Unix,it's best to use a slightly moreinvolvedtechnique:<pre>	extern void func(int);	if(signal(SIGINT, SIG_IGN) != SIG_IGN)		signal(SIGINT, func);</pre>The test and extra callensure that akeyboard interrupttyped in the foreground won't inadvertently interrupt a program running in the background(and it doesn't hurt to code calls to <TT>signal</TT> this way on any system).<a href="pgrps.html" rel=subdocument>[footnote]</a></p><p>On some systems,keyboard interrupthandling is also a function ofthe mode ofthe terminal-input subsystem;see question <a href="cbreak.html">19.1</a>.On somesystems,checking forkeyboard interruptsis only performed when the program is reading input,andkeyboard interrupthandling may therefore depend on which input routines are being called(and <em>whether</em> any input routines are active at all).On MS-DOS systems, <TT>setcbrk</TT>or <TT>ctrlbrk</TT>functionsmay also be involved.</p><p>References:ISO Secs. 7.7,7.7.1<br>H&amp;S Sec. 19.6 pp. 411-3<br>PCS Sec. 12 pp. 210-2<br>POSIX Secs. 3.3.1,3.3.4<br></p><!-- aend --><p><hr><a href="subsecond.html" rev=precedes><img src="../images/buttonleft.gif" alt="prev"></a><a href="index.html" rev=subdocument><img src="../images/buttonup.gif" alt="up"></a><a href="fpexcepts.html" rel=precedes><img src="../images/buttonright.gif" alt="next"></a>&nbsp;<a href="../questions.html"><img src="../images/buttontop.gif" alt="contents"></a><a href="../search.html"><img src="../images/buttonsrch.gif" alt="search"></a><br><!-- lastfooter --><a href="../about.html">about this FAQ list</a>&nbsp;<a href="../eskimo.html">about eskimo</a>&nbsp;<a href="../search.html">search</a>&nbsp;<a href="../feedback.html">feedback</a>&nbsp;<a href="copyright.html">copyright</a><p>Hosted by<a href="http://www.eskimo.com/"><img src="../../www.eskimo.com/img/link/eskitiny.gif" alt="Eskimo North"></a></body><!-- Mirrored from c-faq.com/osdep/sigint.html by HTTrack Website Copier/3.x [XR&CO'2008], Sat, 14 Mar 2009 07:59:04 GMT --></html>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -