Why don't threads get killed in this case?

  • Thread starter grocery_stocker
  • Start date
G

grocery_stocker

Here is the code that is running on OpenBSD 4.2

#!/usr/local/bin/ruby

threads=[]

4.times do |i|
threads=Thread.new do
%x{/usr/libexec/getty std.19200 tty00}
end
end

threads.each{|thr| thr.join}

I run it as a unix background job, I get the following

-bash-3.2$ ./whore.rb &
[1] 11801
-bash-3.2$ ps waux | grep djdoboy
djdoboy 15158 0.0 0.3 844 1540 pi Ss 9:41PM 0:00.05 -
bash
(bash)
djdoboy 11801 0.0 0.4 996 1872 pi S 10:03PM 0:00.01
/usr/local/bin/ruby ./whore.rb
djdoboy 4493 0.0 0.1 372 556 pi S 10:03PM 0:00.02
/usr/libexec/getty std.19200 tty00
djdoboy 19020 0.0 0.1 332 556 pi S 10:03PM 0:00.01
/usr/libexec/getty std.19200 tty00
djdoboy 456 0.0 0.1 364 564 pi S 10:03PM 0:00.02
/usr/libexec/getty std.19200 tty00
djdoboy 11853 0.0 0.1 260 584 pi S 10:03PM 0:00.01
/usr/libexec/getty std.19200 tty00
djdoboy 23871 0.0 0.1 532 408 pi R+ 10:03PM 0:00.00 ps
-waux
djdoboy 27426 0.0 0.1 220 524 pi S+ 10:03PM 0:00.00 grep
djdoboy

Now I get and relogin
-bash-3.2$ exit
logout
Connection closed by foreign host.
[cdalten@localhost ~]$ telnet

-bash-3.2$ ps waux | grep djdoboy
djdoboy 6724 0.0 0.3 1012 1548 p6 Ss 10:04PM 0:00.02 -
bash
(bash)
djdoboy 25303 0.0 0.1 576 448 p6 R+ 10:04PM 0:00.00 ps
-waux
djdoboy 8516 0.0 0.1 1012 408 p6 R+ 10:04PM 0:00.00 grep
djdoboy (bash)
djdoboy 11801 0.0 0.4 996 1872 pi- S 10:03PM 0:00.01
/usr/local/bin/ruby ./whore.rb
djdoboy 11853 0.0 0.1 260 584 pi- I 10:03PM 0:00.01
/usr/libexec/getty std.19200 tty00
djdoboy 456 0.0 0.1 364 564 pi- I 10:03PM 0:00.02
/usr/libexec/getty std.19200 tty00
djdoboy 4493 0.0 0.1 372 556 pi- I 10:03PM 0:00.02
/usr/libexec/getty std.19200 tty00
djdoboy 19020 0.0 0.1 332 556 pi- I 10:03PM 0:00.01
/usr/libexec/getty std.19200 tty00

And the threads are still there. How come ruby threads don't get
killed
on exit? And more to the point, how do I kill them on exit?

Chad
 
J

Jeremy Hinegardner

Hi Chad,

Here is the code that is running on OpenBSD 4.2

#!/usr/local/bin/ruby

threads=[]

4.times do |i|
threads=Thread.new do
%x{/usr/libexec/getty std.19200 tty00}
end
end

threads.each{|thr| thr.join}

I run it as a unix background job, I get the following

-bash-3.2$ ./whore.rb &
[1] 11801
-bash-3.2$ ps waux | grep djdoboy
djdoboy 15158 0.0 0.3 844 1540 pi Ss 9:41PM 0:00.05 -
bash
(bash)
djdoboy 11801 0.0 0.4 996 1872 pi S 10:03PM 0:00.01
/usr/local/bin/ruby ./whore.rb
djdoboy 4493 0.0 0.1 372 556 pi S 10:03PM 0:00.02
/usr/libexec/getty std.19200 tty00
djdoboy 19020 0.0 0.1 332 556 pi S 10:03PM 0:00.01
/usr/libexec/getty std.19200 tty00
djdoboy 456 0.0 0.1 364 564 pi S 10:03PM 0:00.02
/usr/libexec/getty std.19200 tty00
djdoboy 11853 0.0 0.1 260 584 pi S 10:03PM 0:00.01
/usr/libexec/getty std.19200 tty00
djdoboy 23871 0.0 0.1 532 408 pi R+ 10:03PM 0:00.00 ps
-waux
djdoboy 27426 0.0 0.1 220 524 pi S+ 10:03PM 0:00.00 grep
djdoboy

Now I get and relogin
-bash-3.2$ exit
logout
Connection closed by foreign host.
[cdalten@localhost ~]$ telnet

-bash-3.2$ ps waux | grep djdoboy
djdoboy 6724 0.0 0.3 1012 1548 p6 Ss 10:04PM 0:00.02 -
bash
(bash)
djdoboy 25303 0.0 0.1 576 448 p6 R+ 10:04PM 0:00.00 ps
-waux
djdoboy 8516 0.0 0.1 1012 408 p6 R+ 10:04PM 0:00.00 grep
djdoboy (bash)
djdoboy 11801 0.0 0.4 996 1872 pi- S 10:03PM 0:00.01
/usr/local/bin/ruby ./whore.rb
djdoboy 11853 0.0 0.1 260 584 pi- I 10:03PM 0:00.01
/usr/libexec/getty std.19200 tty00
djdoboy 456 0.0 0.1 364 564 pi- I 10:03PM 0:00.02
/usr/libexec/getty std.19200 tty00
djdoboy 4493 0.0 0.1 372 556 pi- I 10:03PM 0:00.02
/usr/libexec/getty std.19200 tty00
djdoboy 19020 0.0 0.1 332 556 pi- I 10:03PM 0:00.01
/usr/libexec/getty std.19200 tty00

And the threads are still there. How come ruby threads don't get
killed
on exit? And more to the point, how do I kill them on exit?


This is not a ruby isssue, this is related to your shell options.

% uname -rs
OpenBSD 4.0
% find ./ -type f > /dev/null &
[1] 6962
% exit

# log back in

% ps -p 6962
PID TT STAT TIME COMMAND
6962 p4 D 0:00.95 find ./ -type f
% kill 6962
% shopt huponexit
huponexit off

man bash:

If the huponexit shell option has been set with shopt,
bash sends a SIGHUP to all jobs when an interactive login
shell exits.

So lets try it.

% shopt -s huponexit
% find ./ -type f > /dev/null &
[1] 29709
% ps -p 29709
PID TT STAT TIME COMMAND
29709 p4 D 0:01.65 find ./ -type f
% exit

# log back in

% ps -p 29709
PID TT STAT TIME COMMAND
%

enjoy,

-jeremy
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,577
Members
45,054
Latest member
LucyCarper

Latest Threads

Top