1

I wrote a bash script, and assigned a keyboard shortcut to trigger the same. Once I hit the shortcut keys, I have no control over it. I want to be able to kill it while it is running. How do I do it?

The problem is that the script takes over key and mouse control, so I cannot start/switch to the terminal while it is running to find the PID and send it a signal.

3
  • this is not a duplicate as OP mention "I cannot start a terminal", I assume OP would find pid using ps.
    – Archemar
    Dec 29, 2017 at 8:50
  • I do not have ssh running
    – HRK
    Dec 29, 2017 at 11:57
  • @HardikKhane Is the script running on a Linux OS? Can you switch to a virtual terminal, via ctrl+alt+F6 or such? If yes, then that would be a way to have a 2nd terminal, to list processes and kill as necessary.
    – mrflash818
    Dec 30, 2017 at 0:21

3 Answers 3

1

Running the script within screen or tmux may help.

If not then you could write a script which kills this process (if it is running) and activate this script via udev when a certain USB device is attached.

2
  • I start the process which works on the GUI by pressing a key combination, and I want to stop it the same way, as the process itself makes mouse clicks, and switching to terminal or any other window messes up things.
    – HRK
    Dec 30, 2017 at 13:36
  • @HardikKhane Maybe it is best to run the process not in your usual environment but with a virtual X server or even in a VM. Dec 30, 2017 at 13:40
0

Have two terminals running, same user.

One terminal is running the script

The second terminal is to monitor, using top or ps aux, and to kill the process from the other terminal, as necessary.

1
  • I start the process which works on the GUI by pressing a key combination, and I want to stop it the same way, as the process itself makes mouse clicks, and switching to terminal or any other window messes up things.
    – HRK
    Feb 8, 2018 at 18:12
0

I wrote another script that kills all the processes(instances) of the original script, and assigned a keyboard shortcut to it. This way once script A is triggered with a key combination, I can kill it instantly with another key combination without the hassle of switching between windows; thereby avoiding messing up things.

Thanks for the the support and ideas though. :)

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .