I have this code:
#include <stdio.h>
#include <stdlib.h>
#include <signal.h>
// Define the function to be called when ctrl-c (SIGINT) signal is sent to process
void
signal_callback_handler(int signum)
{
printf("Caught signal %d\n",signum);
// Cleanup and close up stuff here
// Terminate program
exit(signum);
}
int main()
{
// Register signal and signal handler
signal(SIGINT, signal_callback_handler);
while(1)
{
printf("Program processing stuff here.\n");
sleep(1);
}
return EXIT_SUCCESS;
}
Is there a way to pass an extra argument in the callback function? Something like:
#include <stdio.h>
#include <stdlib.h>
#include <signal.h>
// Define the function to be called when ctrl-c (SIGINT) signal is sent to process
void
signal_callback_handler(int signum, int k)
{
k++; // Changing value of k
}
int main()
{
int k = 0;
// Register signal and signal handler
signal(SIGINT, signal_callback_handler(k);
while(1)
{
printf("Program processing stuff here.\n");
printf(" blah %d\n", k);
sleep(1);
}
return EXIT_SUCCESS;
}
Thank you