The following simple command should demonstrate my issue:
gnome-terminal --tab -t "Tab 1" -e "/bin/bash" --tab -t "Tab 2" -e "/bin/bash"
This should open a new window with two tabs and an active bash shell. If I immediately close this new window using the GUI [x] and then execute a ps command, one (in this case) sub process (/bin/bash) will be left open. I have found out that this corresponds to all inactive tabs that have never been made active (by clicking on them) at some point in time. So if we crafted a new command similar to the example above but with 5 tabs instead of 2 and you immediately closed this window after running the command, 4 sub-processes will be left running. Here is the peculiar part...if you click on each tab to make it active and then close the window, all of the sub-processes will be killed, as one would expect.
Is this a bug in gnome-terminal?
How can I ensure these processes are closed and not left open?
Run like below:
gnome-terminal --tab -t "Tab 1" -e "bash -ic 'echo Hello; exec bash'" --tab -t "Tab 2" -e "bash -ic 'echo Hello; exec bash'"
You need to run some comand before the ;bash and you can change 'echo Hello' by any other.
Related
The following bash script is suppose to open 2 new terminal tabs then execute respective commands:
mate-terminal --tab -e "cd ~/ece344/root; sys161 -w kernel" --tab -e "cd ~/ece344/root; cs161-gdb kernel"
The script does open 2 new tabs however both tabs display the following error:
There was an error creating the child process for this terminal
Failed to execute child process "cd" (No such file or directory)
Ps. The answer should work with mate-terminal.
I don't have mate installed but I would try :
mate-terminal --tab -e "/bin/bash -c 'cd ~/ece344/root; sys161 -w kernel'" --tab -e "/bin/bash -c 'cd ~/ece344/root; cs161-gdb kernel'"
The idea is that "-e" would want to execute a command that probably run inside the window instead of a default shell, so from the error I understand that "cd" is not a real program in an expected location (since 'cd' is in the PATH shouldn't be a problem.
So my example would provide a full path to a shell "/bin/bash" that would then execute the commands you want.
I need to open a new terminal tab and execute multiple commands on it, how can I do it. I have already tried the following,
gnome-terminal --tab -t "X" -e "cd ~/Desktop/terminal_test;mkdir test"
Here I need to cd into a new directory and create a new folder.
Try this:
gnome-terminal -x bash -c "cmd1; cmd2; …cmdN; exec bash"
You can use gnome-terminal. The script below will open 3 tabs running the respective commands..
tab="--tab"
cmd01="bash -c 'ls';'pwd';bash"
foo=""
foo+=($tab -e "$cmd01")
gnome-terminal "${foo[#]}"
exit 0
I would like to create panes in tmux like so :
$ tmux new-session -d -s mysession "while true; do sleep 1; ls; done"
$ tmux split-window -h "while true; do sleep 1; ls -l; done"
Running it this way, when I cancel the command that is running in the pane (window) I close it immediately. How to avoid this behaviour ?
Use the remain-on-exit window option to mark the window (and any panes it contains) to remain after the command it runs exits.
tmux new-session -d -s mysession "while true; do sleep 1; ls; done"
tmux set-option -t mysession:0 remain-on-exit
When you kill the command, the window will remain, and [the pane] will be labeled "Pane is dead". To restart the same command, issue respawn-window. To start a new command in the window (say, an interactive bash session), issue respawn-window bash.
respawn-window (and respawn-pane, which I forgot about but can be use to target an individual pane within a window) also take a -k option, which can be used to kill whatever is running in a window and either restart the command or start a new command. You could add something to your .tmux.conf like
bind-key C-c respawn-pane -k bash
Then, in any active pane, you can type Control-C to kill whatever is running in the pane and replace it with an interactive shell (remain-on-exit would not be necessary in this case, as you are immediately replacing the old command with a new one).
I have a bash script that opens a new gnome terminal with two tabs that runs more scripts. After the scripts in the two tabs finishes, the main script in the parent terminal continues to run.
When I run multiple instances of this bash script, it no longer waits for the additional gnome-terminals to finish before continuing the parent terminal script.
How do I fix it so that the additional instances of the script runs just like the first one?
Here is the bash script that I'm running. I run additional instances of this by typing sh scriptname.sh in a new terminal.
gnome-terminal --tab --command="expect launchneuron.exp" --tab --command="expect launchmpj.exp"
echo "Simulation Complete"
echo "Plotting Results"
expect -c "
set timeout -1
spawn ssh $username#server
expect \"password\"
send \"$password\r\"
expect \"$ \"
send \"qsub -I -q abc -A lc_tb -l nodes=1 -l walltime=24:00:00 -d .\r\"
expect \"$ \"
send \"sh plotgraph.sh\r\"
expect \"$ \"
send \"exit\r\"
"
#!/bin/bash
date
bash -c "sleep 7" &
bash -c "sleep 5" &
wait
date
As you can see while running this script, both sleep commands will run in parallel, but main thread stalls, while they are running.
Sat. Jule 27 01:11:49 2013
Sat. Jule 27 01:11:56 2013
Replace sleep 7 with expect launchneuron.exp
and sleep 5 with expect launchmpj.exp
and add your plot commands after calling "wait":
echo "Simulation Complete"
...(your code to plot results)
I want to run xterm -e file.sh without terminating.
In the file, I'm sending commands to the background and when the script is done, they are still not finished.
What I'm doing currently is:
(cd /myfolder; /xterm -ls -geometry 115x65 -sb -sl 1000)
and then after the window pops up
sh file.sh
exit
What I want to do is something like:
(cd /myfolder; /xterm -ls -geometry 115x65 -sb -sl 1000 -e sh file.sh)
without terminating and wait until the commands in the background finish.
Anyone know how to do that?
Use hold option:
xterm -hold -e file.sh
-hold Turn on the hold resource, i.e., xterm will not immediately destroy its window when the shell command completes. It will wait
until you use the window manager to destroy/kill the window, or if you
use the menu entries that send a signal, e.g., HUP or KILL.
I tried -hold, and it leaves xterm in an unresponsive state that requires closing through non-standard means (the window manager, a kill command). If you would rather have an open shell from which you can exit, try adding that shell to the end of your command:
xterm -e "cd /etc; bash"
I came across the answer on Super User.
Use the wait built-in in you shell script. It'll wait until all the background jobs are finished.
Working Example:
#!/bin/bash
# Script to show usage of wait
sleep 20 &
sleep 20 &
sleep 20 &
sleep 20 &
sleep 20 &
wait
The output
sgulati#maverick:~$ bash test.sh
[1] Done sleep 20
[2] Done sleep 20
[3] Done sleep 20
[4]- Done sleep 20
[5]+ Done sleep 20
sgulati#maverick:~$
Building on a previoius answer, if you specify $SHELL instead of bash, it will use the users preferred shell.
xterm -e "cd /etc; $SHELL"
With respect to creating the separate shell, you'll probably want to run it in the background so that you can continue to execute more commands in the current shell - independent of the separate one. In which case, just add the & operator:
xterm -e "cd /etc; bash" &
PID=$!
<"do stuff while xterm is still running">
wait $PID
The wait command at the end will prevent your primary shell from exiting until the xterm shell does. Without the wait, your xterm shell will still continue to run even after the primary shell exits.