Project

General

Profile

Actions

Bug #6131

closed

Ctrl-C handler do not work from exec process (Windows)

Added by luislavena (Luis Lavena) about 12 years ago. Updated about 12 years ago.

Status:
Closed
Target version:
ruby -v:
ruby 1.9.3-p155 (2012-03-03) [i386-mingw32]
Backport:
[ruby-core:43245]

Description

Hello,

Originally reported to TheCodeShop group: https://groups.google.com/forum/?fromgroups#!topic/thecodeshop/ZI9FY-RKYgs

The usage of "rails server" uses exec to spawn another process to run a server, and that process do not handle Ctrl-C.

Script to recreate this issue:

https://gist.github.com/2009356

=begin a.rb
trap(:INT) do
puts "Hit Ctrl+C in a.rb"
end

exec "ruby b.rb"
=end

=begin b.rb
trap(:INT) do
puts "Hit Ctrl+C in b.rb"
exit(false)
end

sleep
=end

Invoking b directly from command line works, but from a.rb it fails to respond to Ctrl-C


Files

process.patch (9.09 KB) process.patch h.shirosaki (Hiroshi Shirosaki), 04/03/2012 10:44 PM

Related issues 1 (0 open1 closed)

Related to Ruby master - Feature #1952: cannot stop with Ctrl+CClosedko1 (Koichi Sasada)08/18/2009Actions
Actions #1

Updated by shyouhei (Shyouhei Urabe) about 12 years ago

  • Status changed from Open to Assigned
Actions #2

Updated by phasis68 (Heesob Park) about 12 years ago

As you may know, this bug is due to the Revision r34387.

If the CREATE_NEW_PROCESS_GROUP flag is specified in a call to the CreateProcess function, CTRL+C signal is disabled for all processes within the new process group.

I think r34387 is better to be reverted for compatibility with existing applications.

Updated by usa (Usaku NAKAMURA) about 12 years ago

  • Assignee changed from usa (Usaku NAKAMURA) to h.shirosaki (Hiroshi Shirosaki)

r34389 (not 34387) is the revision.

Shirosaki-san, how do you think about this?

Updated by h.shirosaki (Hiroshi Shirosaki) about 12 years ago

How about removing CREATE_NEW_PROCESS_GROUP flag by default and providing a way to specify CREATE_NEW_PROCESS_GROUP flag by spawn methods's arguments?
Ruby user can specify CREATE_NEW_PROCESS_GROUP flag if it's needed.

spawn method has options parameter hash.

spawn(command, options={}) -> Integer
spawn(env, command, options={}) -> Integer
spawn(env, program, *args, options={}) -> Integer

Specify options:
{ :creationflags => Process::CREATE_NEW_PROCESS_GROUP }

Python module does similar things.
http://docs.python.org/library/subprocess.html#subprocess.CREATE_NEW_PROCESS_GROUP

Updated by nobu (Nobuyoshi Nakada) about 12 years ago

h.shirosaki (Hiroshi Shirosaki) wrote:

Specify options:
{ :creationflags => Process::CREATE_NEW_PROCESS_GROUP }

Silly option. Should be 'new_process_group: true' or similar, at least.

Python module does similar things.
http://docs.python.org/library/subprocess.html#subprocess.CREATE_NEW_PROCESS_GROUP

Sigh.

Updated by h.shirosaki (Hiroshi Shirosaki) about 12 years ago

nobu (Nobuyoshi Nakada) wrote:

Should be 'new_process_group: true' or similar, at least.

How about new_pgroup: true? :pgroup option already exists and this is alike pgroup.

I created a patch attached.

  • remove CREATE_NEW_PROCESS_GROUP flag by default
  • add option new_pgroup: true to specify CREATE_NEW_PROCESS_GROUP flag

Any opinions?

Updated by h.shirosaki (Hiroshi Shirosaki) about 12 years ago

  • Assignee changed from h.shirosaki (Hiroshi Shirosaki) to usa (Usaku NAKAMURA)

Assigned to usa-san for comments.

Updated by usa (Usaku NAKAMURA) about 12 years ago

Hello,

In message "[ruby-core:44154] [ruby-trunk - Bug #6131] Ctrl-C handler do not work from exec process (Windows)"
on Apr.06,2012 18:55:27, wrote:

Assigned to usa-san for comments.

Oops, sorry, I overlooked.

I also considered the alternative plan, but I got no idea.
Let it go. Shirosaki-san, please commit it.

Regards,

U.Nakamura

Updated by luislavena (Luis Lavena) about 12 years ago

  • Assignee changed from usa (Usaku NAKAMURA) to h.shirosaki (Hiroshi Shirosaki)

Hiroshi: will be good do this in two commits:

  • First commit that reverts the usage of CREATE_NEW_PROCESS_GROUP, so can be backported to ruby_1_9_3 branch
  • Implement new_pgroup option for spawn.

Thank you.

Actions #10

Updated by Anonymous about 12 years ago

  • Status changed from Assigned to Closed
  • % Done changed from 0 to 100

This issue was solved with changeset r35249.
Luis, thank you for reporting this issue.
Your contribution to Ruby is greatly appreciated.
May Ruby be with you.


  • test/ruby/test_thread.rb
    (TestThreadGroup#test_thread_timer_and_interrupt): skip on Windows.
    Process.kill cannot kill a subprocess if CREATE_NEW_PROCESS_GROUP
    flag is not specified in a call to CreateProcessW().

  • win32/win32.c (CreateChild): revert the usage of
    CREATE_NEW_PROCESS_GROUP flag for compatibility.
    [ruby-core:43245][Bug #6131]

Updated by h.shirosaki (Hiroshi Shirosaki) about 12 years ago

Hi Luis,

Hiroshi: will be good do this in two commits:

  • First commit that reverts the usage of CREATE_NEW_PROCESS_GROUP, so can be backported to ruby_1_9_3 branch
  • Implement new_pgroup option for spawn.

I've committed this in two commits. Please check.

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0