Linux Send Signal

Source: Internet
Author: User
Tags sigint signal

Use the KILL command --To execute the KILL command at the command line. Sends a signal to the specified process.

using the Kill function int Kill (pid_t pid,int  sig); --parameter PID specifies a process to kill, and the sig is the signal to be sent.
//kill function sends a signal#include <stdio.h>#include<stdlib.h>#include<string.h>#include<unistd.h>#include<errno.h>#include<sys/types.h>#include<signal.h>intMainintArgChar*args[]) {    if(arg<2) {printf ("Please enter a parameter! \ n"); return-1; } pid_t PID=atoi (args[1]); intResint=0; Resint=Kill (Pid,sigkill); printf ("The return value is%d\n", Resint);//Printing 0    return 0;}

using the Raise function int raise (int  signum); the kill function sends the signal to the process, and the raise function allows the process to send a signal to itself raise (Signum) is equivalent to Kill (Getpid (), Signum);

int int seconds); seconds is the number of seconds that the timer takes to the back of the clock. If no other timeout is set, the function returns 0, otherwise the return value is the number of seconds left in the previously scheduled timeout. A process can only set a time-out to set seconds to 0 to cancel the previous timeout setting. 
//Capturing signals#include <stdio.h>#include<stdlib.h>#include<string.h>#include<unistd.h>#include<errno.h>#include<signal.h>voidCatch_signal (intSign ) {    Switch(sign) { CaseSIGINT://SIGINT default behavior is to exit the processprintf"SIGINT signal\n"); Exit (0);  Break;  CaseSIGALRM://SIGALRM default behavior is to exit the processprintf"SIGALRM signal\n"); Alarm (5);  Break;  Casesigkill:printf ("SIGKILL signal\n");  Break; }}intMainintArgChar*args[])    {signal (sigint,catch_signal);    Signal (sigalrm,catch_signal);    Signal (sigkill,catch_signal); intI=0; //Alarm signal for permanent circulationAlarm5);  while(1) {printf ("Hello God%d\n", i++); Sleep (1); }    return 0;}

Abort function void abort (void); The function sends a SIGABRT signal to the calling process, and the process should not ignore the signal. Even if the process catches the SIGABRT signal, the process exits unexpectedly so that the process captures the SIGABRT intent that it performs the required cleanup operations before the process terminates. 

Linux Send Signal

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.