I have a signal handler in C++ program:
void term(int signum)
{
cout << "in term" << endl;
# Do Stuff
exit(0);
}
int main(int argc, char *argv[])
{
# Do Stuff
signal(SIGINT, term);
# Do Stuff
}
The program works fine. goes in the function term when I press Ctrl+C and exits.
However, when I try to replicate the behavior using a script, it does not work.
Simplified version of the script I am running:
! /bin/bash
sudo ./program &
rpid=$!
sleep 2
sudo kill -INT $rpid
# sudo kill -TERM $rpid
# sudo kill $rpid
echo "killed"
wait $rpid
The program is does not even go in the term function until I press Ctrl+C. It is stuck on wait indefinitely.