How to check if program ended (Like killing it in TaskManeger or at Shutdown)?
1 2 3 4 5 6 7 8 9 10 11 12
//Something like this
/*#includes*/
int main(int argc, char[] argv){
while (1){
//Do work
if (shutdown) {
//Do work when program ends
//(Work like, write a log or something)
}
}
}
ThangDo is right, in that you can't do anything after the program has been terminated, but on Linux for example (and I assume on other Operating Systems as well), programs can get sent signals. I don't know them all off the top of my head, but I know there is sigterm and sigkill for example. Sigterm tells the program to close down, so you could receive the event a bit like how you did in the code, though Sigkill (I think) just kills the program instead of telling it to close itself.