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