In my C console application, I would like to exit the application and on the same time fire an exit command to close a terminal. However, following code seems not work. Once I run the application, it exit the application, but not close the terminal.
int main(void)
{
system("exit");
return 0;
}
Please give any advise.
The
systemcommand creates a new shell process and issues the command to that shell, so when you issueexitit will close only the new shell.The way to do what you ask for is this:
However, this is A BAD IDEA (for many reasons: you are blindly killing some process that spawned yours with no real clue what it actually is… it could be the user’s login shell, or it could be
init). You probably just want to close the terminal window, right? Then launch your program like this:This will run your program in its own window, which closes when the program finishes. No trickery, and it works with any program.