Function signal () in C

Void function (* signal (int sig, void (* func) (int)) (int) in Library C establishes a function for signal processing (eg a signal handler).

Declaring the signal () function in C

Below is the declaration for signal () function in C:

 void (* signal ( int sig , void (* func )( int )))( int ) 

Parameters

sig - This is a digital signal for a processing function to be set. Listed below are some important digital signals.

macrosignalSIGABRT (Signal Abort) Abnormal termination SIGFPE (Signal Floating-Point Exception) Operation related to arithmetic is not correct, such as dividing by zero or overflow) SIGILL (Signal Illegal Instruction) A function instruction SIGINT (Signal Interrupt) valid signal, usually created by user application SIGSEGV (Signal Segmentation Violation) Invalid access to storage, when a program tries to read or write outside the memory Is allocated to it SIGTERM (Signal Terminate) The end request is sent to the program

func - This is a pointer to a function. This can be a function defined by a programmer or one of the predefined functions:

SIG_DFL Default handling: Signals are handled by the default action for that specific signal. SIG_IGN Ignore the signal: The signal is ignored.

Returns the value

This function returns the previous value of Signal Handler or SIG_ERR on the error.

For example

The following C program illustrates the usage of the signal () function in C:

 #include #include #include #include void sighandler ( int ); int main () { signal ( SIGINT , sighandler ); while ( 1 ) { printf ( "Chuan bi sleep trong mot vai giay .n" ); sleep ( 1 ); } return ( 0 ); } void sighandler ( int signum ) { printf ( "Bat duoc tin hieu %d, chuan bi thoat .n" , signum ); exit ( 1 ); } 

Compiling and running the above C program will create an infinite loop. To exit the program, press CTRL + C.

Function signal () in C Picture 1

According to Tutorialspoint

Previous lesson: Function raise () in C

Next post: signal.h in C

4 ★ | 2 Vote

May be interested

  • Signal and Telegram: Where is the privacy-focused cross-platform chat app better?Signal and Telegram: Where is the privacy-focused cross-platform chat app better?
    the early days of 2021 are witnessing the rise of cross-platform messaging apps focusing on user privacy. for example, telegram and an emerging name that is also receiving a lot of attention lately: signal.
  • Signal - Inviolable App or Promised Land for Criminals?Signal - Inviolable App or Promised Land for Criminals?
    after telegram's policy changes, scam and hacker groups have massively moved to discord and signal platforms.
  • How to fix 'Input Signal Out of Range' error on WindowsHow to fix 'Input Signal Out of Range' error on Windows
    when connecting an external monitor to a windows pc, you may encounter an input signal out of range error. this error usually occurs if you have a high refresh rate monitor connected to a lower end graphics device.
  • How strong is the wireless signal in your Wi-Fi network?How strong is the wireless signal in your Wi-Fi network?
    the performance speed of a wi-fi wireless network connection depends in part on the weak signal strength. between a computer and an access point, the weak signal strength in each direction determines the total amount of bandwidth for that connection.
  • Save time with these text formatting functions in Microsoft ExcelSave time with these text formatting functions in Microsoft Excel
    microsoft excel is a main application for anyone who has to work with numbers, from students to accountants. but its usefulness extends beyond a large database, it can do a lot of great things with text. the functions listed below will help you analyze, edit, convert, change text and save many hours of boring and repetitive tasks.
  • Simple ways to enhance network signal for iPhoneSimple ways to enhance network signal for iPhone
    weak mobile network signal is one of the most annoying things for iphone users, so how to strengthen the network signal on your device?
  • How to speed up Wifi network, increase WiFi signalHow to speed up Wifi network, increase WiFi signal
    how to speed up wifi network, increase wifi signal to the highest level will help stabilize wifi network, better capture wifi for devices connected to wifi network. invite you to consult!
  • How to Hook up a CrossoverHow to Hook up a Crossover
    a crossover is an audio signal processing unit that separates a single stereo audio signal into two, three, or sometimes even four frequency ranges. at a minimum, a crossover ensures that the high-frequency signal (i.e. the treble) goes...
  • Function in programming CFunction in programming C
    a function is a group of commands that go together to perform a task. each c program has at least one function, main (), and all most normal programs define additional functions.
  • DAY function in SQL ServerDAY function in SQL Server
    the day function in sql server returns an integer that is the day of the month (from 1 to 31) from the time passed.