0

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
  • 1
    What is the problem with CTRL+Z? Why do you need to simulate it? Commented Feb 16, 2022 at 10:49

1 Answer 1

2

You can do this with kill. To pause a process do kill -STOP <pid> and to continue it kill -CONT <pid>.

2
  • 1
    This 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. Commented Feb 16, 2022 at 14:41
  • @MC68020, SIGSTOP (as opposed to SIGTSTP) cannot be blocked, ignored or handled. When running CTRL+Z, it actually sends SIGSTP to the process. So if you really want to simulate CTRL+Z, you should use kill -TSTP. It should also be added to the answer, since usually it is better to use SIGTSTP to allow the application to handle it gracefully using a signal handler. SIGSTOP should be use If SIGTSTP fails (due to the signal being blocked/ignored). Commented Feb 16, 2022 at 15:22

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.