私はこのコードを持っています:
#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;
}
コールバック関数で追加の引数を渡す方法はありますか? 何かのようなもの:
#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;
}
ありがとうございました