close one specific GNOME Terminal command












1















I run a loop like this (duration one hour):



#!/bin/bash
gnome-terminal --geometry=50x30 --working-directory=/$HOME/TEST --title terminal1 -e ' sh -c "./FirstAPP; exec bash"'
while true; do
if [ ! pgrep SecondAPP ]; then
gnome-terminal --geometry=50x30 --working-directory=/$HOME/TEST --title terminal2 -e ' sh -c "./SecondAPP; exec bash"'
for ((i=0; i<3600; i+=5)); do
sleep 5
if [ ! pgrep SecondAPP ]; then
break
fi
done
killall -9 SecondAPP > /dev/null 2>&1
# Iwant here a command that closes the gnome-terminal "terminal2"
fi
sleep 5
done


I run this loop and I noticed that in the terminal2 the process got killed but the terminal stays open. Is there a flag or something to close that terminal2?



Or is my implementation wrong?



PS. I am a newbie in Ubuntu, I looked up closing specific terminal, however I dont think it apllies to my case.










share|improve this question

























  • You don't think it applies to your use case, but have you tried the suggested solution?

    – j-money
    Feb 4 at 9:47











  • yes, I tried it. the terminal still opens, I added the nohup flag to the gnome-terminal command

    – user1616685
    Feb 4 at 9:57






  • 1





    Do you really need these to be running in a terminal though? Why are you opening 2 terminals? This only makes your life more complicated.

    – terdon
    Feb 4 at 10:56
















1















I run a loop like this (duration one hour):



#!/bin/bash
gnome-terminal --geometry=50x30 --working-directory=/$HOME/TEST --title terminal1 -e ' sh -c "./FirstAPP; exec bash"'
while true; do
if [ ! pgrep SecondAPP ]; then
gnome-terminal --geometry=50x30 --working-directory=/$HOME/TEST --title terminal2 -e ' sh -c "./SecondAPP; exec bash"'
for ((i=0; i<3600; i+=5)); do
sleep 5
if [ ! pgrep SecondAPP ]; then
break
fi
done
killall -9 SecondAPP > /dev/null 2>&1
# Iwant here a command that closes the gnome-terminal "terminal2"
fi
sleep 5
done


I run this loop and I noticed that in the terminal2 the process got killed but the terminal stays open. Is there a flag or something to close that terminal2?



Or is my implementation wrong?



PS. I am a newbie in Ubuntu, I looked up closing specific terminal, however I dont think it apllies to my case.










share|improve this question

























  • You don't think it applies to your use case, but have you tried the suggested solution?

    – j-money
    Feb 4 at 9:47











  • yes, I tried it. the terminal still opens, I added the nohup flag to the gnome-terminal command

    – user1616685
    Feb 4 at 9:57






  • 1





    Do you really need these to be running in a terminal though? Why are you opening 2 terminals? This only makes your life more complicated.

    – terdon
    Feb 4 at 10:56














1












1








1








I run a loop like this (duration one hour):



#!/bin/bash
gnome-terminal --geometry=50x30 --working-directory=/$HOME/TEST --title terminal1 -e ' sh -c "./FirstAPP; exec bash"'
while true; do
if [ ! pgrep SecondAPP ]; then
gnome-terminal --geometry=50x30 --working-directory=/$HOME/TEST --title terminal2 -e ' sh -c "./SecondAPP; exec bash"'
for ((i=0; i<3600; i+=5)); do
sleep 5
if [ ! pgrep SecondAPP ]; then
break
fi
done
killall -9 SecondAPP > /dev/null 2>&1
# Iwant here a command that closes the gnome-terminal "terminal2"
fi
sleep 5
done


I run this loop and I noticed that in the terminal2 the process got killed but the terminal stays open. Is there a flag or something to close that terminal2?



Or is my implementation wrong?



PS. I am a newbie in Ubuntu, I looked up closing specific terminal, however I dont think it apllies to my case.










share|improve this question
















I run a loop like this (duration one hour):



#!/bin/bash
gnome-terminal --geometry=50x30 --working-directory=/$HOME/TEST --title terminal1 -e ' sh -c "./FirstAPP; exec bash"'
while true; do
if [ ! pgrep SecondAPP ]; then
gnome-terminal --geometry=50x30 --working-directory=/$HOME/TEST --title terminal2 -e ' sh -c "./SecondAPP; exec bash"'
for ((i=0; i<3600; i+=5)); do
sleep 5
if [ ! pgrep SecondAPP ]; then
break
fi
done
killall -9 SecondAPP > /dev/null 2>&1
# Iwant here a command that closes the gnome-terminal "terminal2"
fi
sleep 5
done


I run this loop and I noticed that in the terminal2 the process got killed but the terminal stays open. Is there a flag or something to close that terminal2?



Or is my implementation wrong?



PS. I am a newbie in Ubuntu, I looked up closing specific terminal, however I dont think it apllies to my case.







command-line bash gnome-terminal






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Feb 4 at 10:21









terdon

67.2k13139222




67.2k13139222










asked Feb 4 at 9:06









user1616685user1616685

1155




1155













  • You don't think it applies to your use case, but have you tried the suggested solution?

    – j-money
    Feb 4 at 9:47











  • yes, I tried it. the terminal still opens, I added the nohup flag to the gnome-terminal command

    – user1616685
    Feb 4 at 9:57






  • 1





    Do you really need these to be running in a terminal though? Why are you opening 2 terminals? This only makes your life more complicated.

    – terdon
    Feb 4 at 10:56



















  • You don't think it applies to your use case, but have you tried the suggested solution?

    – j-money
    Feb 4 at 9:47











  • yes, I tried it. the terminal still opens, I added the nohup flag to the gnome-terminal command

    – user1616685
    Feb 4 at 9:57






  • 1





    Do you really need these to be running in a terminal though? Why are you opening 2 terminals? This only makes your life more complicated.

    – terdon
    Feb 4 at 10:56

















You don't think it applies to your use case, but have you tried the suggested solution?

– j-money
Feb 4 at 9:47





You don't think it applies to your use case, but have you tried the suggested solution?

– j-money
Feb 4 at 9:47













yes, I tried it. the terminal still opens, I added the nohup flag to the gnome-terminal command

– user1616685
Feb 4 at 9:57





yes, I tried it. the terminal still opens, I added the nohup flag to the gnome-terminal command

– user1616685
Feb 4 at 9:57




1




1





Do you really need these to be running in a terminal though? Why are you opening 2 terminals? This only makes your life more complicated.

– terdon
Feb 4 at 10:56





Do you really need these to be running in a terminal though? Why are you opening 2 terminals? This only makes your life more complicated.

– terdon
Feb 4 at 10:56










1 Answer
1






active

oldest

votes


















1














You are killing the program SeondApp, but you are not killing the terminal it is running in. The two are separate things. For example, this is the process tree of running gedit in a terminal:



$ gedit &
[1] 13064
$ pstree -s 13064
systemd───systemd───gnome-terminal-───bash───gedit───4*[{gedit}]


Ignore the systemd, that's the init process, everything running on your machine is a child of systemd. Then, what you see there is that gnome-terminal has launched bash which then runs gedit. If you now kill gedit, that won't affect its parents. However, if you kill one of the parents, that will also kill the child.



Normally, what you would do is to use $!, a special variable that holds the PID of the last process launched to the background. Unfortunately, that doesn't with gnome-terminal which seems to have some sort of complicated launching procedure:



$ gnome-terminal &
[1] 23861
$ ps aux | grep 23861
terdon 24341 0.0 0.0 8684 2348 pts/11 S+ 10:59 0:00 grep --color 23861
$ pgrep gnome-terminal
23866


As you can see above, gnome-terminal seem to re-launch itself after launching and uses a different PID. No idea why, but another good reason to use a different terminal.



So, since the standard approach won't work, we need a workaround. What you can do is use kill -$PID which will kil all processes in the process group (from man kill):



-n  where n is larger than 1.  All processes in process  group  n  are
signaled. When an argument of the form '-n' is given, and it is
meant to denote a process group, either a signal must be specified
first, or the argument must be preceded by a '--' option, other‐
wise it will be taken as the signal to send.


Putting all this together, here's a working version of your script:



#!/bin/bash
gnome-terminal --geometry=50x30 --working-directory=/$HOME/TEST --title terminal1
-e ' sh -c "./FirstAPP; exec bash"'
while true; do
if ! pgrep SecondAPP; then
gnome-terminal --geometry=50x30 --working-directory=/$HOME/TEST
--title terminal2 -e 'SecondAPP' &
for ((i=0; i<3600; i+=5)); do
sleep 5
if ! pgrep SecondAPP; then
break
fi
done
## Now, get the PID of SecondAPP
pid=$(pgrep SecondAPP)
## Using -$pid will kill all process in the process group of $pid, so
## it will kill SecondAPP and its parent process, the terminal.
kill -- -$pid
fi
sleep 5
done


Note that I also remove the [ ] around ! pgrep since that was wrong syntax.





I don't see why you are launching terminals at all though. Here's the same idea, without terminals:



#!/bin/bash

$HOME/TEST/FirstAPP
while true; do
if ! pgrep SecondAPP; then
#$HOME/TEST/SecondAPP &
SecondAPP &
pid=$!
for ((i=0; i<3600; i+=5)); do
sleep 5
if ! pgrep SecondAPP; then
break
fi
done
kill $pid
fi
sleep 5
done




Finally, this feels like a strange way of doing things. You might want to ask a new question, explain what you are trying to do and why and we can see if we can find a simpler approach for whatever it is you need.






share|improve this answer
























  • thanks I'll give it a try, I use terminals, because they need to show me some progress within that terminal, however I need to kill them every hour

    – user1616685
    Feb 4 at 11:41











  • @user1616685 ah, I see. I would still probably use xterm instead of gnome-terminal though. Gnome-terminal is very complex and heavy, and you don't need any of its fancy features here.

    – terdon
    Feb 4 at 12:02











  • I tried to use xterm, however flags like working directory are not working

    – user1616685
    Feb 5 at 10:51











  • @user1616685 yeah, you'd do it with -e "cd $HOME/TEST && ./FirstAPP or even just $HOME/TEST/FirstAPP, if you don't really need to run it from that dir.

    – terdon
    Feb 5 at 10:58











  • thanks, I execute the xterm command, but the code stays at that line, opens the firstAPP and paused there, when I CTRL+C then the code goes on.

    – user1616685
    Feb 5 at 11:19











Your Answer








StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "89"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f1115475%2fclose-one-specific-gnome-terminal-command%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









1














You are killing the program SeondApp, but you are not killing the terminal it is running in. The two are separate things. For example, this is the process tree of running gedit in a terminal:



$ gedit &
[1] 13064
$ pstree -s 13064
systemd───systemd───gnome-terminal-───bash───gedit───4*[{gedit}]


Ignore the systemd, that's the init process, everything running on your machine is a child of systemd. Then, what you see there is that gnome-terminal has launched bash which then runs gedit. If you now kill gedit, that won't affect its parents. However, if you kill one of the parents, that will also kill the child.



Normally, what you would do is to use $!, a special variable that holds the PID of the last process launched to the background. Unfortunately, that doesn't with gnome-terminal which seems to have some sort of complicated launching procedure:



$ gnome-terminal &
[1] 23861
$ ps aux | grep 23861
terdon 24341 0.0 0.0 8684 2348 pts/11 S+ 10:59 0:00 grep --color 23861
$ pgrep gnome-terminal
23866


As you can see above, gnome-terminal seem to re-launch itself after launching and uses a different PID. No idea why, but another good reason to use a different terminal.



So, since the standard approach won't work, we need a workaround. What you can do is use kill -$PID which will kil all processes in the process group (from man kill):



-n  where n is larger than 1.  All processes in process  group  n  are
signaled. When an argument of the form '-n' is given, and it is
meant to denote a process group, either a signal must be specified
first, or the argument must be preceded by a '--' option, other‐
wise it will be taken as the signal to send.


Putting all this together, here's a working version of your script:



#!/bin/bash
gnome-terminal --geometry=50x30 --working-directory=/$HOME/TEST --title terminal1
-e ' sh -c "./FirstAPP; exec bash"'
while true; do
if ! pgrep SecondAPP; then
gnome-terminal --geometry=50x30 --working-directory=/$HOME/TEST
--title terminal2 -e 'SecondAPP' &
for ((i=0; i<3600; i+=5)); do
sleep 5
if ! pgrep SecondAPP; then
break
fi
done
## Now, get the PID of SecondAPP
pid=$(pgrep SecondAPP)
## Using -$pid will kill all process in the process group of $pid, so
## it will kill SecondAPP and its parent process, the terminal.
kill -- -$pid
fi
sleep 5
done


Note that I also remove the [ ] around ! pgrep since that was wrong syntax.





I don't see why you are launching terminals at all though. Here's the same idea, without terminals:



#!/bin/bash

$HOME/TEST/FirstAPP
while true; do
if ! pgrep SecondAPP; then
#$HOME/TEST/SecondAPP &
SecondAPP &
pid=$!
for ((i=0; i<3600; i+=5)); do
sleep 5
if ! pgrep SecondAPP; then
break
fi
done
kill $pid
fi
sleep 5
done




Finally, this feels like a strange way of doing things. You might want to ask a new question, explain what you are trying to do and why and we can see if we can find a simpler approach for whatever it is you need.






share|improve this answer
























  • thanks I'll give it a try, I use terminals, because they need to show me some progress within that terminal, however I need to kill them every hour

    – user1616685
    Feb 4 at 11:41











  • @user1616685 ah, I see. I would still probably use xterm instead of gnome-terminal though. Gnome-terminal is very complex and heavy, and you don't need any of its fancy features here.

    – terdon
    Feb 4 at 12:02











  • I tried to use xterm, however flags like working directory are not working

    – user1616685
    Feb 5 at 10:51











  • @user1616685 yeah, you'd do it with -e "cd $HOME/TEST && ./FirstAPP or even just $HOME/TEST/FirstAPP, if you don't really need to run it from that dir.

    – terdon
    Feb 5 at 10:58











  • thanks, I execute the xterm command, but the code stays at that line, opens the firstAPP and paused there, when I CTRL+C then the code goes on.

    – user1616685
    Feb 5 at 11:19
















1














You are killing the program SeondApp, but you are not killing the terminal it is running in. The two are separate things. For example, this is the process tree of running gedit in a terminal:



$ gedit &
[1] 13064
$ pstree -s 13064
systemd───systemd───gnome-terminal-───bash───gedit───4*[{gedit}]


Ignore the systemd, that's the init process, everything running on your machine is a child of systemd. Then, what you see there is that gnome-terminal has launched bash which then runs gedit. If you now kill gedit, that won't affect its parents. However, if you kill one of the parents, that will also kill the child.



Normally, what you would do is to use $!, a special variable that holds the PID of the last process launched to the background. Unfortunately, that doesn't with gnome-terminal which seems to have some sort of complicated launching procedure:



$ gnome-terminal &
[1] 23861
$ ps aux | grep 23861
terdon 24341 0.0 0.0 8684 2348 pts/11 S+ 10:59 0:00 grep --color 23861
$ pgrep gnome-terminal
23866


As you can see above, gnome-terminal seem to re-launch itself after launching and uses a different PID. No idea why, but another good reason to use a different terminal.



So, since the standard approach won't work, we need a workaround. What you can do is use kill -$PID which will kil all processes in the process group (from man kill):



-n  where n is larger than 1.  All processes in process  group  n  are
signaled. When an argument of the form '-n' is given, and it is
meant to denote a process group, either a signal must be specified
first, or the argument must be preceded by a '--' option, other‐
wise it will be taken as the signal to send.


Putting all this together, here's a working version of your script:



#!/bin/bash
gnome-terminal --geometry=50x30 --working-directory=/$HOME/TEST --title terminal1
-e ' sh -c "./FirstAPP; exec bash"'
while true; do
if ! pgrep SecondAPP; then
gnome-terminal --geometry=50x30 --working-directory=/$HOME/TEST
--title terminal2 -e 'SecondAPP' &
for ((i=0; i<3600; i+=5)); do
sleep 5
if ! pgrep SecondAPP; then
break
fi
done
## Now, get the PID of SecondAPP
pid=$(pgrep SecondAPP)
## Using -$pid will kill all process in the process group of $pid, so
## it will kill SecondAPP and its parent process, the terminal.
kill -- -$pid
fi
sleep 5
done


Note that I also remove the [ ] around ! pgrep since that was wrong syntax.





I don't see why you are launching terminals at all though. Here's the same idea, without terminals:



#!/bin/bash

$HOME/TEST/FirstAPP
while true; do
if ! pgrep SecondAPP; then
#$HOME/TEST/SecondAPP &
SecondAPP &
pid=$!
for ((i=0; i<3600; i+=5)); do
sleep 5
if ! pgrep SecondAPP; then
break
fi
done
kill $pid
fi
sleep 5
done




Finally, this feels like a strange way of doing things. You might want to ask a new question, explain what you are trying to do and why and we can see if we can find a simpler approach for whatever it is you need.






share|improve this answer
























  • thanks I'll give it a try, I use terminals, because they need to show me some progress within that terminal, however I need to kill them every hour

    – user1616685
    Feb 4 at 11:41











  • @user1616685 ah, I see. I would still probably use xterm instead of gnome-terminal though. Gnome-terminal is very complex and heavy, and you don't need any of its fancy features here.

    – terdon
    Feb 4 at 12:02











  • I tried to use xterm, however flags like working directory are not working

    – user1616685
    Feb 5 at 10:51











  • @user1616685 yeah, you'd do it with -e "cd $HOME/TEST && ./FirstAPP or even just $HOME/TEST/FirstAPP, if you don't really need to run it from that dir.

    – terdon
    Feb 5 at 10:58











  • thanks, I execute the xterm command, but the code stays at that line, opens the firstAPP and paused there, when I CTRL+C then the code goes on.

    – user1616685
    Feb 5 at 11:19














1












1








1







You are killing the program SeondApp, but you are not killing the terminal it is running in. The two are separate things. For example, this is the process tree of running gedit in a terminal:



$ gedit &
[1] 13064
$ pstree -s 13064
systemd───systemd───gnome-terminal-───bash───gedit───4*[{gedit}]


Ignore the systemd, that's the init process, everything running on your machine is a child of systemd. Then, what you see there is that gnome-terminal has launched bash which then runs gedit. If you now kill gedit, that won't affect its parents. However, if you kill one of the parents, that will also kill the child.



Normally, what you would do is to use $!, a special variable that holds the PID of the last process launched to the background. Unfortunately, that doesn't with gnome-terminal which seems to have some sort of complicated launching procedure:



$ gnome-terminal &
[1] 23861
$ ps aux | grep 23861
terdon 24341 0.0 0.0 8684 2348 pts/11 S+ 10:59 0:00 grep --color 23861
$ pgrep gnome-terminal
23866


As you can see above, gnome-terminal seem to re-launch itself after launching and uses a different PID. No idea why, but another good reason to use a different terminal.



So, since the standard approach won't work, we need a workaround. What you can do is use kill -$PID which will kil all processes in the process group (from man kill):



-n  where n is larger than 1.  All processes in process  group  n  are
signaled. When an argument of the form '-n' is given, and it is
meant to denote a process group, either a signal must be specified
first, or the argument must be preceded by a '--' option, other‐
wise it will be taken as the signal to send.


Putting all this together, here's a working version of your script:



#!/bin/bash
gnome-terminal --geometry=50x30 --working-directory=/$HOME/TEST --title terminal1
-e ' sh -c "./FirstAPP; exec bash"'
while true; do
if ! pgrep SecondAPP; then
gnome-terminal --geometry=50x30 --working-directory=/$HOME/TEST
--title terminal2 -e 'SecondAPP' &
for ((i=0; i<3600; i+=5)); do
sleep 5
if ! pgrep SecondAPP; then
break
fi
done
## Now, get the PID of SecondAPP
pid=$(pgrep SecondAPP)
## Using -$pid will kill all process in the process group of $pid, so
## it will kill SecondAPP and its parent process, the terminal.
kill -- -$pid
fi
sleep 5
done


Note that I also remove the [ ] around ! pgrep since that was wrong syntax.





I don't see why you are launching terminals at all though. Here's the same idea, without terminals:



#!/bin/bash

$HOME/TEST/FirstAPP
while true; do
if ! pgrep SecondAPP; then
#$HOME/TEST/SecondAPP &
SecondAPP &
pid=$!
for ((i=0; i<3600; i+=5)); do
sleep 5
if ! pgrep SecondAPP; then
break
fi
done
kill $pid
fi
sleep 5
done




Finally, this feels like a strange way of doing things. You might want to ask a new question, explain what you are trying to do and why and we can see if we can find a simpler approach for whatever it is you need.






share|improve this answer













You are killing the program SeondApp, but you are not killing the terminal it is running in. The two are separate things. For example, this is the process tree of running gedit in a terminal:



$ gedit &
[1] 13064
$ pstree -s 13064
systemd───systemd───gnome-terminal-───bash───gedit───4*[{gedit}]


Ignore the systemd, that's the init process, everything running on your machine is a child of systemd. Then, what you see there is that gnome-terminal has launched bash which then runs gedit. If you now kill gedit, that won't affect its parents. However, if you kill one of the parents, that will also kill the child.



Normally, what you would do is to use $!, a special variable that holds the PID of the last process launched to the background. Unfortunately, that doesn't with gnome-terminal which seems to have some sort of complicated launching procedure:



$ gnome-terminal &
[1] 23861
$ ps aux | grep 23861
terdon 24341 0.0 0.0 8684 2348 pts/11 S+ 10:59 0:00 grep --color 23861
$ pgrep gnome-terminal
23866


As you can see above, gnome-terminal seem to re-launch itself after launching and uses a different PID. No idea why, but another good reason to use a different terminal.



So, since the standard approach won't work, we need a workaround. What you can do is use kill -$PID which will kil all processes in the process group (from man kill):



-n  where n is larger than 1.  All processes in process  group  n  are
signaled. When an argument of the form '-n' is given, and it is
meant to denote a process group, either a signal must be specified
first, or the argument must be preceded by a '--' option, other‐
wise it will be taken as the signal to send.


Putting all this together, here's a working version of your script:



#!/bin/bash
gnome-terminal --geometry=50x30 --working-directory=/$HOME/TEST --title terminal1
-e ' sh -c "./FirstAPP; exec bash"'
while true; do
if ! pgrep SecondAPP; then
gnome-terminal --geometry=50x30 --working-directory=/$HOME/TEST
--title terminal2 -e 'SecondAPP' &
for ((i=0; i<3600; i+=5)); do
sleep 5
if ! pgrep SecondAPP; then
break
fi
done
## Now, get the PID of SecondAPP
pid=$(pgrep SecondAPP)
## Using -$pid will kill all process in the process group of $pid, so
## it will kill SecondAPP and its parent process, the terminal.
kill -- -$pid
fi
sleep 5
done


Note that I also remove the [ ] around ! pgrep since that was wrong syntax.





I don't see why you are launching terminals at all though. Here's the same idea, without terminals:



#!/bin/bash

$HOME/TEST/FirstAPP
while true; do
if ! pgrep SecondAPP; then
#$HOME/TEST/SecondAPP &
SecondAPP &
pid=$!
for ((i=0; i<3600; i+=5)); do
sleep 5
if ! pgrep SecondAPP; then
break
fi
done
kill $pid
fi
sleep 5
done




Finally, this feels like a strange way of doing things. You might want to ask a new question, explain what you are trying to do and why and we can see if we can find a simpler approach for whatever it is you need.







share|improve this answer












share|improve this answer



share|improve this answer










answered Feb 4 at 11:09









terdonterdon

67.2k13139222




67.2k13139222













  • thanks I'll give it a try, I use terminals, because they need to show me some progress within that terminal, however I need to kill them every hour

    – user1616685
    Feb 4 at 11:41











  • @user1616685 ah, I see. I would still probably use xterm instead of gnome-terminal though. Gnome-terminal is very complex and heavy, and you don't need any of its fancy features here.

    – terdon
    Feb 4 at 12:02











  • I tried to use xterm, however flags like working directory are not working

    – user1616685
    Feb 5 at 10:51











  • @user1616685 yeah, you'd do it with -e "cd $HOME/TEST && ./FirstAPP or even just $HOME/TEST/FirstAPP, if you don't really need to run it from that dir.

    – terdon
    Feb 5 at 10:58











  • thanks, I execute the xterm command, but the code stays at that line, opens the firstAPP and paused there, when I CTRL+C then the code goes on.

    – user1616685
    Feb 5 at 11:19



















  • thanks I'll give it a try, I use terminals, because they need to show me some progress within that terminal, however I need to kill them every hour

    – user1616685
    Feb 4 at 11:41











  • @user1616685 ah, I see. I would still probably use xterm instead of gnome-terminal though. Gnome-terminal is very complex and heavy, and you don't need any of its fancy features here.

    – terdon
    Feb 4 at 12:02











  • I tried to use xterm, however flags like working directory are not working

    – user1616685
    Feb 5 at 10:51











  • @user1616685 yeah, you'd do it with -e "cd $HOME/TEST && ./FirstAPP or even just $HOME/TEST/FirstAPP, if you don't really need to run it from that dir.

    – terdon
    Feb 5 at 10:58











  • thanks, I execute the xterm command, but the code stays at that line, opens the firstAPP and paused there, when I CTRL+C then the code goes on.

    – user1616685
    Feb 5 at 11:19

















thanks I'll give it a try, I use terminals, because they need to show me some progress within that terminal, however I need to kill them every hour

– user1616685
Feb 4 at 11:41





thanks I'll give it a try, I use terminals, because they need to show me some progress within that terminal, however I need to kill them every hour

– user1616685
Feb 4 at 11:41













@user1616685 ah, I see. I would still probably use xterm instead of gnome-terminal though. Gnome-terminal is very complex and heavy, and you don't need any of its fancy features here.

– terdon
Feb 4 at 12:02





@user1616685 ah, I see. I would still probably use xterm instead of gnome-terminal though. Gnome-terminal is very complex and heavy, and you don't need any of its fancy features here.

– terdon
Feb 4 at 12:02













I tried to use xterm, however flags like working directory are not working

– user1616685
Feb 5 at 10:51





I tried to use xterm, however flags like working directory are not working

– user1616685
Feb 5 at 10:51













@user1616685 yeah, you'd do it with -e "cd $HOME/TEST && ./FirstAPP or even just $HOME/TEST/FirstAPP, if you don't really need to run it from that dir.

– terdon
Feb 5 at 10:58





@user1616685 yeah, you'd do it with -e "cd $HOME/TEST && ./FirstAPP or even just $HOME/TEST/FirstAPP, if you don't really need to run it from that dir.

– terdon
Feb 5 at 10:58













thanks, I execute the xterm command, but the code stays at that line, opens the firstAPP and paused there, when I CTRL+C then the code goes on.

– user1616685
Feb 5 at 11:19





thanks, I execute the xterm command, but the code stays at that line, opens the firstAPP and paused there, when I CTRL+C then the code goes on.

– user1616685
Feb 5 at 11:19


















draft saved

draft discarded




















































Thanks for contributing an answer to Ask Ubuntu!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f1115475%2fclose-one-specific-gnome-terminal-command%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Questions related to Moebius Transform of Characteristic Function of the Primes

List of scandals in India

Can not write log (Is /dev/pts mounted?) - openpty in Ubuntu-on-Windows?