I have this code:
#include <stdio.h> #include <signal.h> void signal_handler(int signal) { printf("Caught signal in CHILD.\n"); } int main(void) { int s; signal(SIGTSTP, signal_handler); while(1){ printf("%s@%s/# ",getlogin(),get_current_dir_name()); scanf("%d",&s); } return 0; } when i run the code it prints:
something: ^ZCaught signal in CHILD. As far i understand that the scanf doesn't execute when i press the ctr-z. Although after the printf inside my function it goes straight to the scanf, waits for input and then starts the loop again.Is there any way to avoid scanf when i press ctr-z and start the while loop again? I tried something like that
void signal_handler(int signal) { printf("Caught signal in CHILD.\n"); printf("%s@%s/# ",getlogin(),get_current_dir_name()); } but it didn't work. After the second printf goes straight to the scanf, waits for input and then starts the loop again. Can i, somehow, start the loop again?