At work we have a supercomputer accessible via SSH.
We login, reserve the cores using bsub
command with parameters, and the latter creates (from doc) "an interactive bash session with pseudo-terminal."
In that "pseudo-terminal" we then go to a folder, start the solver with parameters and let it run to completion.
So the app completes and the session stays open, and the reserved cores remain reserved, then a couple days later (if the sim finished Friday after work) the IT sends an email on Monday stating that the cores are reserved, but they see no activity, blah blah blah...
I've checked https://stackoverflow.com/questions/14254118/waiting-for-background-processes-to-finish-before-exiting-script and Bash - how to run a command after the previous finished? and other forums/tutorials, but all I find is how to keep an application running after closing the terminal (detaching the application from a terminal).
I need the opposite, I want to close the terminal (this can be the last step of the solver, so it could exit the terminal and be killed)
I am open to suggestions, I can do it in a script, or I can get the guy to code it in his C++ solver.
I tried the following (on my Ubuntu Server running in a VM, expect this to work more or less the same in any bash
environment, please correct me if I'm wrong):
delay_test.c:
#include <stdio.h>
#include <unistd.h>
int main(int argc, const char *argv[])
{
printf("Doing some fake lengthy operation...");
sleep(15); // sleep for 15 seconds
return 0;
}
Compiles and runs as expected. I tried system("clear");
(part of stdlib.h
) before returning, and that works too, I get the message, then 15 seconds later the screen is cleared and the app exits.
Then I tried system("exit");
and nothing happens (I mean the app exits as if that exit
statement wasn't there...). My best guess is that the app has to return before one can exit the terminal, but it's only a guess.
I also tried a script way:
test.sh:
#!/bin/bash
./delay_test &
wait
exit
In this case, my understanding tells me that the exit
statement is to finish the script, but I need to exit out of the terminal session once the app in question terminates.
So what can I do to force the "pseudo-terminal" to exit after the app exits?
exec whateveryourappis
in the shell to replace the shell with that app that will exit (and thus close the ptty) when it exits? – thrig Oct 28 '16 at 17:01exec thesolver
to replace the provided shell with whatever your solver is? – thrig Oct 28 '16 at 17:17bsub
with some parameters to reserve the cores on a supercomputer and it creates a bash shell for me, I don't control this process. In that sub-shell I run our solver. – nurchi Oct 28 '16 at 17:30exec
did. Sorry. I just tried it in my local VM, works like a charm. Please answer this question (vs comment) so I can mark it appropriately. Thanks. – nurchi Oct 28 '16 at 17:31command -parameters ;exit
worked as well. – nurchi Oct 28 '16 at 17:34