{"id":3310,"date":"2025-07-29T21:09:41","date_gmt":"2025-07-29T20:09:41","guid":{"rendered":"https:\/\/workboot.fr\/ciela\/?page_id=3310"},"modified":"2025-07-30T14:23:42","modified_gmt":"2025-07-30T13:23:42","slug":"sigint-en-c","status":"publish","type":"page","link":"https:\/\/workboot.fr\/ciela\/sigint-en-c\/","title":{"rendered":"SIGINT en C"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">La fonction signal en c<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">En C, la fonction&nbsp;<code>signal()<\/code>&nbsp;est utilis\u00e9e pour g\u00e9rer les&nbsp;<strong>signaux<\/strong>, qui sont des notifications asynchrones envoy\u00e9es \u00e0 un processus par le syst\u00e8me d&rsquo;exploitation ou par un autre processus. Elle permet de d\u00e9finir un&nbsp;<strong>gestionnaire de signal<\/strong>&nbsp;(une fonction de rappel) qui sera ex\u00e9cut\u00e9 lorsque le processus re\u00e7oit un signal sp\u00e9cifique.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Prototype de&nbsp;<code>signal()<\/code><\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#include &lt;signal.h&gt;\nvoid (*signal(int sig, void (*handler)(int)))(int);<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong><code>sig<\/code><\/strong>&nbsp;: Le num\u00e9ro du signal \u00e0 intercepter (ex:&nbsp;<code>SIGINT<\/code>,&nbsp;<code>SIGSEGV<\/code>).<\/li>\n\n\n\n<li><strong><code>handler<\/code><\/strong>&nbsp;: Un pointeur vers la fonction de gestion du signal.<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Valeurs de retour<\/strong><\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li>En cas de succ\u00e8s,&nbsp;<code>signal()<\/code>&nbsp;renvoie l&rsquo;ancien gestionnaire.<\/li>\n\n\n\n<li>En cas d&rsquo;\u00e9chec, elle renvoie&nbsp;<code>SIG_ERR<\/code>&nbsp;et d\u00e9finit&nbsp;<code>errno<\/code>.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Le cas de SIGINT<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\"><a href=\"https:\/\/workboot.fr\/ciela\/signaux-clavier-dans-le-terminal-linux\/\">SIGINT<\/a> est provoqu\u00e9 par une interruption ctrl c<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"c\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">#include &lt;stdio.h>\n#include &lt;stdlib.h>\n#include &lt;signal.h>\n#include &lt;unistd.h>\n\n\/* Fonction de gestion du signal SIGINT *\/\nvoid sigint_handler(int sig) {\n    (void)sig;  \/* \u00c9vite un avertissement \"unused parameter\" *\/\n    write(STDOUT_FILENO, \"\\nSignal SIGINT intercept\u00e9 (Ctrl+C)\\n\", 34);\n    exit(EXIT_SUCCESS);  \/* Macro EXIT_SUCCESS de stdlib.h *\/\n}\n\nint main(void) {\n    \/* Configuration du gestionnaire de signal *\/\n    if (signal(SIGINT, sigint_handler) == SIG_ERR) {\n        perror(\"Erreur lors de la configuration du gestionnaire de signal\");\n        exit(EXIT_FAILURE);  \/* Macro EXIT_FAILURE de stdlib.h *\/\n    }\n\n    printf(\"Le programme est en cours d'ex\u00e9cution...\\n\");\n    printf(\"Appuyez sur Ctrl+C pour d\u00e9clencher SIGINT.\\n\");\n\n    \/* Boucle infinie pour garder le programme actif *\/\n    while (1) {\n        sleep(1);\n    }\n\n    return EXIT_SUCCESS;  \/* Macro EXIT_SUCCESS de stdlib.h *\/\n}<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Compilation:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>gcc -std=c89 -ansi -pedantic -Wall -Wextra sigint_example.c -o sigint_example<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">vous pouvez tester directement le code<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Avec gdb<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>gcc -g -std=c89 -ansi -pedantic -Wall -Wextra sigint_example.c -o sigint_example<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Dans gdb il faudra d\u00e9sactiver gdb \u00e0 la r\u00e9action de  SIGINT pour utiliser notre programme.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">la commande pour ,ne pas stopper gdb , ne pas afficher par gdb, et passer<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">handle SIGINT nostop noprint pass<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">signal avec kill<\/h2>\n\n\n\n<pre class=\"wp-block-preformatted\">kill -SIGINT PID<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">ou<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>kill -2 PID<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Ignorer un signal avec&nbsp;<code>SIG_IGN<\/code><\/strong><\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">exemple :<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"c\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">#include &lt;stdio.h>\n#include &lt;signal.h>\n#include &lt;unistd.h>\n\nint main() {\n    \/\/ Ignorer SIGINT (Ctrl+C n'aura plus d'effet)\n    signal(SIGINT, SIG_IGN);\n\n    printf(\"Essayez Ctrl+C, cela ne fera rien...\\n\");\n    while (1) {\n        sleep(1);\n    }\n\n    return 0;\n}<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>R\u00e9tablir le comportement par d\u00e9faut avec&nbsp;<code>SIG_DFL<\/code><\/strong><\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Exemple pour r\u00e9tablir<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"c\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">#include &lt;stdio.h>\n#include &lt;signal.h>\n#include &lt;unistd.h>\n\nint main() {\n    \/\/ R\u00e9tablir le comportement par d\u00e9faut de SIGINT\n    signal(SIGINT, SIG_DFL);\n\n    printf(\"Ctrl+C terminera le processus.\\n\");\n    while (1) {\n        sleep(1);\n    }\n\n    return 0;\n}<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Signaux courants en C<\/strong><\/h3>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><thead><tr><th class=\"has-text-align-left\" data-align=\"left\">Signal<\/th><th class=\"has-text-align-left\" data-align=\"left\">Description<\/th><th class=\"has-text-align-left\" data-align=\"left\">D\u00e9clenchement classique<\/th><\/tr><\/thead><tbody><tr><td><code>SIGINT<\/code><\/td><td>Interruption (Ctrl+C)<\/td><td><code>kill -2<\/code>&nbsp;ou Ctrl+C<\/td><\/tr><tr><td><code>SIGTERM<\/code><\/td><td>Demande de terminaison<\/td><td><code>kill -15<\/code>&nbsp;(par d\u00e9faut)<\/td><\/tr><tr><td><code>SIGKILL<\/code><\/td><td>Terminaison forc\u00e9e (ne peut \u00eatre captur\u00e9)<\/td><td><code>kill -9<\/code><\/td><\/tr><tr><td><code>SIGSEGV<\/code><\/td><td>Erreur de segmentation<\/td><td>Acc\u00e8s m\u00e9moire invalide<\/td><\/tr><tr><td><code>SIGALRM<\/code><\/td><td>Alarme (utilis\u00e9 avec&nbsp;<code>alarm()<\/code>)<\/td><td>Timer expir\u00e9<\/td><\/tr><\/tbody><\/table><\/figure>\n","protected":false},"excerpt":{"rendered":"<p>La fonction signal en c En C, la fonction&nbsp;signal()&nbsp;est utilis\u00e9e pour g\u00e9rer les&nbsp;signaux, qui sont des notifications asynchrones envoy\u00e9es \u00e0 un processus par le syst\u00e8me d&rsquo;exploitation ou par un autre [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"_crdt_document":"","_uag_custom_page_level_css":"","footnotes":""},"class_list":["post-3310","page","type-page","status-publish","hentry"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.3 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>SIGINT en C - workboot<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/workboot.fr\/ciela\/sigint-en-c\/\" \/>\n<meta property=\"og:locale\" content=\"fr_FR\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"SIGINT en C - workboot\" \/>\n<meta property=\"og:description\" content=\"La fonction signal en c En C, la fonction&nbsp;signal()&nbsp;est utilis\u00e9e pour g\u00e9rer les&nbsp;signaux, qui sont des notifications asynchrones envoy\u00e9es \u00e0 un processus par le syst\u00e8me d&rsquo;exploitation ou par un autre [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/workboot.fr\/ciela\/sigint-en-c\/\" \/>\n<meta property=\"og:site_name\" content=\"workboot\" \/>\n<meta property=\"article:modified_time\" content=\"2025-07-30T13:23:42+00:00\" \/>\n<meta name=\"twitter:label1\" content=\"Dur\u00e9e de lecture estim\u00e9e\" \/>\n\t<meta name=\"twitter:data1\" content=\"1 minute\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/workboot.fr\\\/ciela\\\/sigint-en-c\\\/\",\"url\":\"https:\\\/\\\/workboot.fr\\\/ciela\\\/sigint-en-c\\\/\",\"name\":\"SIGINT en C - workboot\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/workboot.fr\\\/ciela\\\/#website\"},\"datePublished\":\"2025-07-29T20:09:41+00:00\",\"dateModified\":\"2025-07-30T13:23:42+00:00\",\"inLanguage\":\"fr-FR\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/workboot.fr\\\/ciela\\\/sigint-en-c\\\/\"]}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/workboot.fr\\\/ciela\\\/#website\",\"url\":\"https:\\\/\\\/workboot.fr\\\/ciela\\\/\",\"name\":\"workboot\",\"description\":\"Open Source, Open Minds \",\"publisher\":{\"@id\":\"https:\\\/\\\/workboot.fr\\\/ciela\\\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/workboot.fr\\\/ciela\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"fr-FR\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/workboot.fr\\\/ciela\\\/#organization\",\"name\":\"workboot\",\"url\":\"https:\\\/\\\/workboot.fr\\\/ciela\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"fr-FR\",\"@id\":\"https:\\\/\\\/workboot.fr\\\/ciela\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/workboot.fr\\\/ciela\\\/wp-content\\\/uploads\\\/2025\\\/05\\\/logo_ciel-dorian-1.png\",\"contentUrl\":\"https:\\\/\\\/workboot.fr\\\/ciela\\\/wp-content\\\/uploads\\\/2025\\\/05\\\/logo_ciel-dorian-1.png\",\"width\":1024,\"height\":950,\"caption\":\"workboot\"},\"image\":{\"@id\":\"https:\\\/\\\/workboot.fr\\\/ciela\\\/#\\\/schema\\\/logo\\\/image\\\/\"}}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"SIGINT en C - workboot","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/workboot.fr\/ciela\/sigint-en-c\/","og_locale":"fr_FR","og_type":"article","og_title":"SIGINT en C - workboot","og_description":"La fonction signal en c En C, la fonction&nbsp;signal()&nbsp;est utilis\u00e9e pour g\u00e9rer les&nbsp;signaux, qui sont des notifications asynchrones envoy\u00e9es \u00e0 un processus par le syst\u00e8me d&rsquo;exploitation ou par un autre [&hellip;]","og_url":"https:\/\/workboot.fr\/ciela\/sigint-en-c\/","og_site_name":"workboot","article_modified_time":"2025-07-30T13:23:42+00:00","twitter_misc":{"Dur\u00e9e de lecture estim\u00e9e":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/workboot.fr\/ciela\/sigint-en-c\/","url":"https:\/\/workboot.fr\/ciela\/sigint-en-c\/","name":"SIGINT en C - workboot","isPartOf":{"@id":"https:\/\/workboot.fr\/ciela\/#website"},"datePublished":"2025-07-29T20:09:41+00:00","dateModified":"2025-07-30T13:23:42+00:00","inLanguage":"fr-FR","potentialAction":[{"@type":"ReadAction","target":["https:\/\/workboot.fr\/ciela\/sigint-en-c\/"]}]},{"@type":"WebSite","@id":"https:\/\/workboot.fr\/ciela\/#website","url":"https:\/\/workboot.fr\/ciela\/","name":"workboot","description":"Open Source, Open Minds ","publisher":{"@id":"https:\/\/workboot.fr\/ciela\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/workboot.fr\/ciela\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"fr-FR"},{"@type":"Organization","@id":"https:\/\/workboot.fr\/ciela\/#organization","name":"workboot","url":"https:\/\/workboot.fr\/ciela\/","logo":{"@type":"ImageObject","inLanguage":"fr-FR","@id":"https:\/\/workboot.fr\/ciela\/#\/schema\/logo\/image\/","url":"https:\/\/workboot.fr\/ciela\/wp-content\/uploads\/2025\/05\/logo_ciel-dorian-1.png","contentUrl":"https:\/\/workboot.fr\/ciela\/wp-content\/uploads\/2025\/05\/logo_ciel-dorian-1.png","width":1024,"height":950,"caption":"workboot"},"image":{"@id":"https:\/\/workboot.fr\/ciela\/#\/schema\/logo\/image\/"}}]}},"uagb_featured_image_src":{"full":false,"thumbnail":false,"medium":false,"medium_large":false,"large":false,"1536x1536":false,"2048x2048":false},"uagb_author_info":{"display_name":"admin","author_link":"https:\/\/workboot.fr\/ciela\/author\/admin\/"},"uagb_comment_info":0,"uagb_excerpt":"La fonction signal en c En C, la fonction&nbsp;signal()&nbsp;est utilis\u00e9e pour g\u00e9rer les&nbsp;signaux, qui sont des notifications asynchrones envoy\u00e9es \u00e0 un processus par le syst\u00e8me d&rsquo;exploitation ou par un autre [&hellip;]","_links":{"self":[{"href":"https:\/\/workboot.fr\/ciela\/wp-json\/wp\/v2\/pages\/3310","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/workboot.fr\/ciela\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/workboot.fr\/ciela\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/workboot.fr\/ciela\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/workboot.fr\/ciela\/wp-json\/wp\/v2\/comments?post=3310"}],"version-history":[{"count":10,"href":"https:\/\/workboot.fr\/ciela\/wp-json\/wp\/v2\/pages\/3310\/revisions"}],"predecessor-version":[{"id":3346,"href":"https:\/\/workboot.fr\/ciela\/wp-json\/wp\/v2\/pages\/3310\/revisions\/3346"}],"wp:attachment":[{"href":"https:\/\/workboot.fr\/ciela\/wp-json\/wp\/v2\/media?parent=3310"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}