rgcaldas Posted October 16, 2007 at 09:37 AM Report Share #140379 Posted October 16, 2007 at 09:37 AM Boas Ando à procura de como apanhar os sinais SIGINT (tipo Ctrl-C) para poder executar alguma acção antes de terminar o programa. A ideia não é apanhar um tecla, mas o sinal do sistema, e alterar o seu comportamento. Alguém tem para ai um bookmark que aprofunde este assunto. Obrigado Link to comment Share on other sites More sharing options...
Rui Carlos Posted October 16, 2007 at 09:44 AM Report Share #140380 Posted October 16, 2007 at 09:44 AM void func(int signum) { puts("Sinal Recebido"); } int main() { if(signal(SIGINT, func)==SIG_ERR) { perror("signal"); exit(1); } sleep(10); return 0; } Quando o programa receber o sinal SIGINT, vai executar a função func. Usas a função signal para alterar o comportamento associado ao sinal. Rui Carlos Gonçalves Link to comment Share on other sites More sharing options...
rgcaldas Posted October 16, 2007 at 11:09 AM Author Report Share #140412 Posted October 16, 2007 at 11:09 AM Brutal 5 estrelas, obrigado Rui Carlos Se mais alguém precisar encontrei isto http://www.delorie.com/djgpp/doc/libc/libc_724.html Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now