Shell script running binaries in multiple terminals
Clash Royale CLAN TAG#URR8PPP
up vote
0
down vote
favorite
I'm pretty new to shell scripts but I have some binaries I'd like to run in a loop over a set of different input files. I need them to be run in sequence: repeat after current one complete.
I got as far as trying to run two process in separate terminals and saving the pid but when I go to kill the process, it looks like the pids have changed.
#!/bin/bash
gnome-terminal -e "vi" & MAIN_PID=$!
gnome-terminal -e "gedit" & SIM_PID=$!
echo "MAIN Process ID is " $MAIN_PID
echo "SIM Process ID is " $SIM_PID
sudo kill $MAIN_PID
Terminal Output:
MAIN Process ID is 8532
SIM Process ID is 8542
# Option âÂÂ-eâ is deprecated and might be removed in a later version of gnome-terminal.
# Use âÂÂ-- â to terminate the options and put the command line to execute after it.
kill: (8532): No such process
user:~/Desktop$ ps -A | grep vi
1026 ? 00:00:01 dconf-service
8541 pts/3 00:00:00 vi
user:~/Desktop$ ps -A | grep gedit
8550 pts/4 00:00:00 gedit
If there's an easier way to get what I want started, I'd like to know as well. I was planning to start these processes and check some condition to know when they have completed, kill the process and repeat with different set of inputs.
shell-script
add a comment |Â
up vote
0
down vote
favorite
I'm pretty new to shell scripts but I have some binaries I'd like to run in a loop over a set of different input files. I need them to be run in sequence: repeat after current one complete.
I got as far as trying to run two process in separate terminals and saving the pid but when I go to kill the process, it looks like the pids have changed.
#!/bin/bash
gnome-terminal -e "vi" & MAIN_PID=$!
gnome-terminal -e "gedit" & SIM_PID=$!
echo "MAIN Process ID is " $MAIN_PID
echo "SIM Process ID is " $SIM_PID
sudo kill $MAIN_PID
Terminal Output:
MAIN Process ID is 8532
SIM Process ID is 8542
# Option âÂÂ-eâ is deprecated and might be removed in a later version of gnome-terminal.
# Use âÂÂ-- â to terminate the options and put the command line to execute after it.
kill: (8532): No such process
user:~/Desktop$ ps -A | grep vi
1026 ? 00:00:01 dconf-service
8541 pts/3 00:00:00 vi
user:~/Desktop$ ps -A | grep gedit
8550 pts/4 00:00:00 gedit
If there's an easier way to get what I want started, I'd like to know as well. I was planning to start these processes and check some condition to know when they have completed, kill the process and repeat with different set of inputs.
shell-script
add a comment |Â
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I'm pretty new to shell scripts but I have some binaries I'd like to run in a loop over a set of different input files. I need them to be run in sequence: repeat after current one complete.
I got as far as trying to run two process in separate terminals and saving the pid but when I go to kill the process, it looks like the pids have changed.
#!/bin/bash
gnome-terminal -e "vi" & MAIN_PID=$!
gnome-terminal -e "gedit" & SIM_PID=$!
echo "MAIN Process ID is " $MAIN_PID
echo "SIM Process ID is " $SIM_PID
sudo kill $MAIN_PID
Terminal Output:
MAIN Process ID is 8532
SIM Process ID is 8542
# Option âÂÂ-eâ is deprecated and might be removed in a later version of gnome-terminal.
# Use âÂÂ-- â to terminate the options and put the command line to execute after it.
kill: (8532): No such process
user:~/Desktop$ ps -A | grep vi
1026 ? 00:00:01 dconf-service
8541 pts/3 00:00:00 vi
user:~/Desktop$ ps -A | grep gedit
8550 pts/4 00:00:00 gedit
If there's an easier way to get what I want started, I'd like to know as well. I was planning to start these processes and check some condition to know when they have completed, kill the process and repeat with different set of inputs.
shell-script
I'm pretty new to shell scripts but I have some binaries I'd like to run in a loop over a set of different input files. I need them to be run in sequence: repeat after current one complete.
I got as far as trying to run two process in separate terminals and saving the pid but when I go to kill the process, it looks like the pids have changed.
#!/bin/bash
gnome-terminal -e "vi" & MAIN_PID=$!
gnome-terminal -e "gedit" & SIM_PID=$!
echo "MAIN Process ID is " $MAIN_PID
echo "SIM Process ID is " $SIM_PID
sudo kill $MAIN_PID
Terminal Output:
MAIN Process ID is 8532
SIM Process ID is 8542
# Option âÂÂ-eâ is deprecated and might be removed in a later version of gnome-terminal.
# Use âÂÂ-- â to terminate the options and put the command line to execute after it.
kill: (8532): No such process
user:~/Desktop$ ps -A | grep vi
1026 ? 00:00:01 dconf-service
8541 pts/3 00:00:00 vi
user:~/Desktop$ ps -A | grep gedit
8550 pts/4 00:00:00 gedit
If there's an easier way to get what I want started, I'd like to know as well. I was planning to start these processes and check some condition to know when they have completed, kill the process and repeat with different set of inputs.
shell-script
shell-script
asked Aug 23 at 14:36
woahs
1
1
add a comment |Â
add a comment |Â
1 Answer
1
active
oldest
votes
up vote
0
down vote
When you run gnome-terminal -e "vi" & MAIN_PID=$!
, you are not capturing the PID of vi
in MAIN_PID
; you are capturing the PID of that instance of gnome-terminal
. If you want to find the PID of a process owned by gnome_terminal
, you could do some magic on the output of pstree
:
pstree -p $MAIN_PID | grep -o 'vim([0-9]*) | grep -o '[0-9]*'
To check whether a process still exists, you can use kill -0
which will not send any signals, and either return with an exit code of 0 if the process exists, or 1 if it does not.
add a comment |Â
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
When you run gnome-terminal -e "vi" & MAIN_PID=$!
, you are not capturing the PID of vi
in MAIN_PID
; you are capturing the PID of that instance of gnome-terminal
. If you want to find the PID of a process owned by gnome_terminal
, you could do some magic on the output of pstree
:
pstree -p $MAIN_PID | grep -o 'vim([0-9]*) | grep -o '[0-9]*'
To check whether a process still exists, you can use kill -0
which will not send any signals, and either return with an exit code of 0 if the process exists, or 1 if it does not.
add a comment |Â
up vote
0
down vote
When you run gnome-terminal -e "vi" & MAIN_PID=$!
, you are not capturing the PID of vi
in MAIN_PID
; you are capturing the PID of that instance of gnome-terminal
. If you want to find the PID of a process owned by gnome_terminal
, you could do some magic on the output of pstree
:
pstree -p $MAIN_PID | grep -o 'vim([0-9]*) | grep -o '[0-9]*'
To check whether a process still exists, you can use kill -0
which will not send any signals, and either return with an exit code of 0 if the process exists, or 1 if it does not.
add a comment |Â
up vote
0
down vote
up vote
0
down vote
When you run gnome-terminal -e "vi" & MAIN_PID=$!
, you are not capturing the PID of vi
in MAIN_PID
; you are capturing the PID of that instance of gnome-terminal
. If you want to find the PID of a process owned by gnome_terminal
, you could do some magic on the output of pstree
:
pstree -p $MAIN_PID | grep -o 'vim([0-9]*) | grep -o '[0-9]*'
To check whether a process still exists, you can use kill -0
which will not send any signals, and either return with an exit code of 0 if the process exists, or 1 if it does not.
When you run gnome-terminal -e "vi" & MAIN_PID=$!
, you are not capturing the PID of vi
in MAIN_PID
; you are capturing the PID of that instance of gnome-terminal
. If you want to find the PID of a process owned by gnome_terminal
, you could do some magic on the output of pstree
:
pstree -p $MAIN_PID | grep -o 'vim([0-9]*) | grep -o '[0-9]*'
To check whether a process still exists, you can use kill -0
which will not send any signals, and either return with an exit code of 0 if the process exists, or 1 if it does not.
answered Aug 23 at 15:51
DopeGhoti
41.1k55080
41.1k55080
add a comment |Â
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f464421%2fshell-script-running-binaries-in-multiple-terminals%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password