You have few options. One is to stop the script (CtrlZ), get the PID of the script and send SIGKILL
to the process group.
When a command is executed in a shell, the process it starts and all its children are part of the same process group (in this case, the foreground process group). To send a signal to all processes in this group, you send it to the process leader. For the kill
command, process leader is denoted thus:
kill -PID
Where PID
is the process ID of the script.
Example:
Consider a script test.sh
which launches some processes. Say you ran it in a shell:
$ ./test.sh
In another terminal,
$ pgrep test.sh
17802
$ pstree -ps `!!`
pstree -ps `pgrep test.sh`
init(1)───sshd(1211)───sshd(17312)───sshd(17372)───zsh(17788)───test.sh(17802)─┬─dd(17804)
├─sleep(17805)
└─yes(17803)
In this case, to send a signal to process group created by test.sh
, you'd do:
kill -INT -17802
-INT
is used to send SIGINT
, and so this command is the equivalent of pressing CtrlC on the terminal. To send SIGKILL
:
kill -KILL -17802
You only need to stop the script if you can't open another terminal. If you can, use pgrep
to find the PID.
One of the commands that the script launches may be trapping SIGINT
, which is probably why CtrlC is ineffective. However, SIGKILL
can't be trapped, and it is usually a last-resort option. You might want to try SIGTERM
(-TERM
) before going for the kill. Neither SIGKILL
or SIGTERM
can be set up as a keyboard shortcut the way SIGINT
is.
All this is moot if your script doesn't contain a shebang line. From this SO answer:
Usually the parent shell guesses that the script is written for the the same shell (minimal Bourne-like shells run the script with /bin/sh, bash runs it as a bash subprocess) ...
Because of this, when the script is executed, you won't find a process named after script (or a process with the script's name in the command line) and pgrep
will fail.
Always use a shebang line.
Use sys.argv[1]
so that the filename is taken from the arguments:
import sys
with open(sys.argv[1],'r') as in_file
Then, you can use various methods to pass the filename as an argument. For example, with find
:
find test/ -type f -name '*.csv' -exec /path/to/script.py {} \;
Best Answer
First, open a terminator instance, split it into 4 panes as desired and save as a new layout (make sure to close all open terminal windows except the one you've set up with your new profile). For each of the 4 panes, add a custom command but just add the text
COMMAND1
,COMMAND2
etc. Save the new layout asfoo
(or whatever). At this point, your~/.config/terminator/config
should look something like this:Now, modify your bash script to replace
COMMANDN
with the actual command you need to run:Running that script will now open a new terminal window with 4 panes, each running one of your commands.
Important: if the command is something that runs and then exits (as opposed to something like
top
which runs until you tell it to stop), you needCOMMAN; bash
as the command so that a new shell will be started. Otherwise, the command will run and the shell will exit immediately. That's why I have; bash
after each command excepttop
in y script.