# Killing a gnome-terminal process from a ruby script

**URL:** <https://www.ruby-forum.com/t/killing-a-gnome-terminal-process-from-a-ruby-script/193401>\
**Category:** Ruby\
**Created:** [August 17, 2010, 6:10am UTC](https://www.ruby-forum.com/t/killing-a-gnome-terminal-process-from-a-ruby-script/193401 "2010-08-17T06:10:59Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![fasterrain](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/cab0a1/32.png) [@fasterrain](https://www.ruby-forum.com/u/fasterrain)\
**Post date:** [August 17, 2010, 6:10am UTC](https://www.ruby-forum.com/t/killing-a-gnome-terminal-process-from-a-ruby-script/193401/1 "2010-08-17T06:10:59Z")

</div>

Hello:

I’m working on a dialog manager and I’m stuck at the part where I need  
to launch a terminal process and also kill it.  
This is what I have so far.

Launch:  
@terminal\_pid = IO.popen(‘gnome-terminal’)  
Kill  
Process.kill :SIGTERM, @terminal\_pid.pid if !@terminal\_pid.nil?

That method seems to work for stuff such as google-chrome, gcalctool,  
pidgin, however it has no effect on gnome-terminal nor gedit.

The Ruby script runs within a terminal window itself so I have no  
interest in “kill -9 ‘gnome-terminal’”. I am trying to kill only that  
specific @terminal\_pid

Can anyone explain what is going on or a way of fixing it?

Thank you in advance!

PS:

---

<div class="post-metadata">

**Author:** ![fasterrain](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/cab0a1/32.png) [@fasterrain](https://www.ruby-forum.com/u/fasterrain)\
**Post date:** [August 17, 2010, 6:26am UTC](https://www.ruby-forum.com/t/killing-a-gnome-terminal-process-from-a-ruby-script/193401/2 "2010-08-17T06:26:43Z")

</div>

On 8/16/2010 10:11 PM, Lg Lg wrote:

> PS:

Processes such as gnome-terminal are free to ignore sigterm, and many  
do. If you want to force the process to die, you want sigkill (the  
equivalent of kill -9). Good manners says you should first try sigterm  
to give a process a chance to exit gracefully before sending sigkill.

---

<div class="post-metadata">

**Author:** ![fasterrain](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/cab0a1/32.png) [@fasterrain](https://www.ruby-forum.com/u/fasterrain)\
**Post date:** [August 17, 2010, 10:03am UTC](https://www.ruby-forum.com/t/killing-a-gnome-terminal-process-from-a-ruby-script/193401/3 "2010-08-17T10:03:47Z")

</div>

Walton H. wrote:

> On 8/16/2010 10:11 PM, Lg Lg wrote:
> 
> > PS:
> 
> Processes such as gnome-terminal are free to ignore sigterm, and many  
> do. If you want to force the process to die, you want sigkill (the  
> equivalent of kill -9). Good manners says you should first try sigterm  
> to give a process a chance to exit gracefully before sending sigkill.

I tired both:  
Process.kill :SIGKILL, @terminal\_pid.pid if !@terminal\_pid.nil?  
and  
`kill -9 #{@terminal_pid.pid}`

but the terminal window won’t close.

I know that if I do something like pkill -9 ‘gnome-terminal’ it will  
work, but the thing is that I am interested in killing only that last  
window that ‘gnome-terminal’ created.
