Ubuntu – Closing a Specific Terminal

14.04gnome-terminal

I have a program that opens a new terminal and runs while loop, but when the program ends I want to terminate this window. Is it possible to close a certain terminal window with a command, while keeping all other terminals open?

Best Answer

Njap

The easy way: Create a variable that the while loop tests for true (or false, whatever way you like) and change this var to end the loop.

The complicated way: Get the Pid of you Shell:

$ echo $$

returns e.g.

1441

The Shell (e.g. bash) runs in the Terminal, so the Terminal is identified by bashs parent PID. Get ppid:

$ cat /proc/1441/status | grep PPid

returns e.g.

1432

If you can Pid it, you can kill it. ;)

$ kill 1432

EDIT: There might be easier ways to get the Pid of the program process, e.g. if the program has a specific name, you can

$ ps aux | grep nameofmyspecificprogram

for it.