Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Kill doesn't work on Ubuntu #1

Open
aishfenton opened this issue Aug 25, 2010 · 8 comments
Open

Kill doesn't work on Ubuntu #1

aishfenton opened this issue Aug 25, 2010 · 8 comments

Comments

@aishfenton
Copy link

When we issue a @process.kill on ubuntu it doesn't kill it (even if we use INT). Digging in a little it looks like @process.id is the wrong pid, hence kill doesn't work.

On Ubuntu when the process is run, it runs "sh -c [my command]", which then spawns the actual command. This appears to be different from OS X where the command is executed directly (as the ruby doc implies would happen).

I assume(?) that it's the extra "sh -c" process that's causing the pid to be incorrect, since it's pointing at the "sh -c" process rather than the real command process.

We're stuck. Any help appreciated, and happy to work on it with you.

Aish

PS. The same script is working fine on OS X.

@timcharper
Copy link
Owner

That's really weird... especially since BackgroundProcess is specifically using 'exec' to execute the command... I don't know how much more 'exec-y' you can get.

I've tried it on an ubuntu karmic machine, and it appears to work fine:

irb(main):004:0> bp = BackgroundProcess.run("sleep 100")
=> #<BackgroundProcess:0x7ff34e8ba828 @stderr=#<IO:0x7ff34e8bada0>, @stdout=#<IO:0x7ff34e8bb1b0>, @stdin=#<IO:0x7ff34e8bb430>, @pid=22329>
irb(main):005:0> 
[1]+  Stopped                 irb
root@utility:~ $ ps aux -H | grep 'sleep 100' -A5 -B5
root      1678  0.0  0.0  18652   532 ?        Ss   Mar31   0:00   cron
root      1703  0.0  0.0  49004   356 ?        Ss   Mar31   0:03   /usr/sbin/sshd
root     22204  0.0  0.0  80920  3528 ?        Ss   05:34   0:00     sshd: root@pts/4 
root     22261  0.0  0.0  18408  2612 pts/4    Ss   05:35   0:00       -bash
root     22306  0.1  0.2  46524 11564 pts/4    T    05:36   0:00         irb                          
root     22329  0.0  0.0   8096   592 pts/4    T    05:37   0:00           sleep 100
root     22335  0.0  0.0  14952  1056 pts/4    R+   05:38   0:00         ps aux -H
root     22336  0.0  0.0   5992   644 pts/4    S+   05:38   0:00         grep sleep 100 -A5 -B5
root      1708  0.0  0.0   5916    64 tty1     Ss+  Mar31   0:00   /sbin/getty -8 38400 tty1
root      9451  0.0  0.0  36944   636 ?        Ss   Apr01   0:00   /usr/lib/postfix/master
postfix   9455  0.0  0.0  39164   912 ?        S    Apr01   0:00     qmgr -l -t fifo -u
postfix  22194  0.0  0.0  39004  2116 ?        S    05:28   0:00     pickup -l -t fifo -u
104      10408  0.0  0.0  23280   776 ?        Ss   Apr01   0:00   dbus-daemon --system --fork
root@utility:~ $ fg
irb
bp.pid
=> 22329
irb(main):006:0> 
[1]+  Stopped                 irb

root@utility:~ $ cat /etc/apt/sources.list
deb http://archive.ubuntu.com/ubuntu/ karmic main restricted universe multiverse
deb-src http://archive.ubuntu.com/ubuntu/ karmic main restricted universe multiverse

deb http://archive.ubuntu.com/ubuntu/ karmic-updates main restricted universe multiverse
deb-src http://archive.ubuntu.com/ubuntu/ karmic-updates main restricted universe multiverse

deb http://security.ubuntu.com/ubuntu karmic-security main restricted universe multiverse
deb-src http://security.ubuntu.com/ubuntu karmic-security main restricted universe multiverse

@timcharper
Copy link
Owner

which ruby version are you using? Is it the same between OS X and your Ubuntu machine?

@aishfenton
Copy link
Author

We're using ruby 1.8.7 (patchlevel 174) on both.

We'll see if we can reproduce it with a simpler script and upload it (at the moment we're using BackgroundProcess from within a Cucumber script, but I don't think that this is causing the issue).

@timcharper
Copy link
Owner

are you using output redirectors?

irb(main):007:0*   bp = BackgroundProcess.run("sleep 100 > 1")
=> #<BackgroundProcess:0x7ff34e88fd08 @stderr=#<IO:0x7ff34e88fdf8>, @stdout=#<IO:0x7ff34e88fee8>, @stdin=#<IO:0x7ff34e88ff60>, @pid=22411>
irb(main):008:0> 
[1]+  Stopped                 irb
root@utility:~ $ ps aux -H | grep 'sleep 100' -A5 -B5
root     22204  0.0  0.0  80920  3528 ?        Ss   05:34   0:00     sshd: root@pts/4 
root     22261  0.0  0.0  18408  2624 pts/4    Ss   05:35   0:00       -bash
root     22306  0.0  0.2  46536 11568 pts/4    T    05:36   0:00         irb                          
root     22411  0.0  0.0   3928   564 pts/4    T    06:04   0:00           sh -c sleep 100 > 1
root     22412  0.0  0.0   8092   588 pts/4    T    06:04   0:00             sleep 100
root     22418  0.0  0.0  14948  1052 pts/4    R+   06:04   0:00         ps aux -H
root     22419  0.0  0.0   6000   648 pts/4    S+   06:04   0:00         grep sleep 100 -A5 -B5
root      1708  0.0  0.0   5916    64 tty1     Ss+  Mar31   0:00   /sbin/getty -8 38400 tty1
root      9451  0.0  0.0  36944   636 ?        Ss   Apr01   0:00   /usr/lib/postfix/master
postfix   9455  0.0  0.0  39164   912 ?        S    Apr01   0:00     qmgr -l -t fifo -u
postfix  22194  0.0  0.0  39004  2180 ?        S    05:28   0:00     pickup -l -t fifo -u
104      10408  0.0  0.0  23280   776 ?        Ss   Apr01   0:00   dbus-daemon --system --fork

@aishfenton
Copy link
Author

No, but we're explicitly running ruby (maybe with relative paths), which might?

ruby -rubygems bin/my_script args

When you

@aishfenton
Copy link
Author

When it uses the "sh -c ... " version. Does kill work for you?

@aishfenton
Copy link
Author

Just tried running this on OS X. It actually causes an orphan process to be left behind too.
So probably nothing to do with Ubuntu.

require 'rubygems'
require 'background_process'

bp = BackgroundProcess.run("sleep 100 > 1")

sleep(2)

bp.kill
bp.wait

@timcharper
Copy link
Owner

I don't believe it would.

I'm curious to see if that's what's reproducing it. Can you record a screencast with jing or something and share it to demonstrate the problem? Or terminal output?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants