I'm trying to run several mongod processes through a Java Application using ProcessBuilder, is there a way to simulate Ctrl+Z keypress to pause the current mongod process ?
1 Answer
You can do this with kill. To pause a process do
kill -STOP <pid> and to continue it kill -CONT <pid>.
-
1This will work at the condition the process killed handles SIGSTOP/SIGCONT in some other way than SIG_IGN. Applied to mongodb processes, OP should check, I remember that (long time ago) mongodb had no proper support for these signals. Sure things might have changed so check first. Anyhow whenever killing whatever, always first check that the signal is handled according to what you expect.MC68020– MC680202022-02-16 14:41:02 +00:00Commented Feb 16, 2022 at 14:41
-
@MC68020,
SIGSTOP(as opposed toSIGTSTP) cannot be blocked, ignored or handled. When running CTRL+Z, it actually sendsSIGSTPto the process. So if you really want to simulate CTRL+Z, you should usekill -TSTP. It should also be added to the answer, since usually it is better to useSIGTSTPto allow the application to handle it gracefully using a signal handler.SIGSTOPshould be use IfSIGTSTPfails (due to the signal being blocked/ignored).aviro– aviro2022-02-16 15:22:39 +00:00Commented Feb 16, 2022 at 15:22