Details

    • Type: Bug Bug
    • Status: Closed Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: JRuby 1.1.2
    • Fix Version/s: JRuby 1.x+
    • Component/s: Windows
    • Labels:
      None
    • Environment:
      mswin32
    • Number of attachments :
      0

      Description

      MRIs Process documentation explicitly defines a return value of 0 on Windows while current JRuby raises an exception.

        Activity

        Hide
        Vladimir Sizikov added a comment -

        Corrected the category.

        Show
        Vladimir Sizikov added a comment - Corrected the category.
        Hide
        Daniel Berger added a comment -

        It's possible to get the ppid on Windows, with the caveat that the parent may have exited.

        It should be possible to implement this properly with CreateToolhelp32Snapshot + Process32First/Next.

        Show
        Daniel Berger added a comment - It's possible to get the ppid on Windows, with the caveat that the parent may have exited. It should be possible to implement this properly with CreateToolhelp32Snapshot + Process32First/Next.
        Hide
        Daniel Berger added a comment -

        Here's the implementation I'm using in Sapphire. Works like a champ:

        #ifdef _WIN32
        #include <tlhelp32.h>
        #endif
        
        static VALUE get_ppid(VALUE self)
        {
           VALUE v_ppid;
        
        #ifdef _WIN32
           HANDLE handle;
           PROCESSENTRY32 proc_entry;
           int pid = getpid();
           v_ppid = INT2FIX(0);
        
           rb_secure(2);
        
           if(pid){
              handle = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
        
              if(handle == INVALID_HANDLE_VALUE)
                 rb_sys_fail(0);
        
              proc_entry.dwSize = sizeof(PROCESSENTRY32);
        
              if(!Process32First(handle, &proc_entry)){
                 errno = GetLastError();
                 CloseHandle(handle);
                 rb_sys_fail(0);
              }
        
              while(Process32Next(handle, &proc_entry)){
                 if(proc_entry.th32ProcessID == pid){
                    v_ppid = INT2FIX(proc_entry.th32ParentProcessID);
                    break;
                 }
              }
        
              CloseHandle(handle);
           }
        #else
           rb_secure(2);
           v_ppid = INT2FIX(getppid());
        #endif
        
           return v_ppid;
        }
        
        Show
        Daniel Berger added a comment - Here's the implementation I'm using in Sapphire. Works like a champ: #ifdef _WIN32 #include <tlhelp32.h> #endif static VALUE get_ppid(VALUE self) { VALUE v_ppid; #ifdef _WIN32 HANDLE handle; PROCESSENTRY32 proc_entry; int pid = getpid(); v_ppid = INT2FIX(0); rb_secure(2); if(pid){ handle = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0); if(handle == INVALID_HANDLE_VALUE) rb_sys_fail(0); proc_entry.dwSize = sizeof(PROCESSENTRY32); if(!Process32First(handle, &proc_entry)){ errno = GetLastError(); CloseHandle(handle); rb_sys_fail(0); } while(Process32Next(handle, &proc_entry)){ if(proc_entry.th32ProcessID == pid){ v_ppid = INT2FIX(proc_entry.th32ParentProcessID); break; } } CloseHandle(handle); } #else rb_secure(2); v_ppid = INT2FIX(getppid()); #endif return v_ppid; }
        Hide
        Charles Oliver Nutter added a comment -

        While I have no question that Daniel's code works and is a better way to get ppid, we're somewhat constrained by what's roughly specified for Ruby (and the original bug even asked for that behavior), and the code given is, if nothing else, a little problematic to try to implement solely through JNA. We'd love help implementing that, but I would request that a separate bug be opened for adding "enhanced ppid on Windows" functionality so we can track progress there.

        Show
        Charles Oliver Nutter added a comment - While I have no question that Daniel's code works and is a better way to get ppid, we're somewhat constrained by what's roughly specified for Ruby (and the original bug even asked for that behavior), and the code given is, if nothing else, a little problematic to try to implement solely through JNA. We'd love help implementing that, but I would request that a separate bug be opened for adding "enhanced ppid on Windows" functionality so we can track progress there.
        Hide
        Vladimir Sizikov added a comment -

        This issue has not been fully fixed.

        On windows:

        jruby -e "p Process.ppid" #===>
        :1: ppid unsupported on this platform (NotImplementedError)

        Show
        Vladimir Sizikov added a comment - This issue has not been fully fixed. On windows: jruby -e "p Process.ppid" #===> :1: ppid unsupported on this platform (NotImplementedError)
        Hide
        Thomas E Enebo added a comment -

        Fixed in commit 7206 on trunk

        Show
        Thomas E Enebo added a comment - Fixed in commit 7206 on trunk
        Hide
        Vladimir Sizikov added a comment -

        Sorry, reopening this again, since while Process.ppid works with x32 JVM, but it still raises NotImplementedError on Windows x64 on JDK x64.

        Show
        Vladimir Sizikov added a comment - Sorry, reopening this again, since while Process.ppid works with x32 JVM, but it still raises NotImplementedError on Windows x64 on JDK x64.
        Hide
        Thomas E Enebo added a comment -

        bumping until we have a JNA which support win32-amd64. This only affects 64 bit windows.

        Show
        Thomas E Enebo added a comment - bumping until we have a JNA which support win32-amd64. This only affects 64 bit windows.
        Hide
        Hiro Asari added a comment -

        This appears to be fixed.

        $ jruby -v -e "p Process.ppid"
        jruby 1.6.0.dev (ruby 1.8.7 patchlevel 249) (2010-07-26 49cf9ce) (Java HotSpot(T
        M) 64-Bit Server VM 1.6.0_21) [amd64-java]
        0
        
        Show
        Hiro Asari added a comment - This appears to be fixed. $ jruby -v -e "p Process.ppid" jruby 1.6.0.dev (ruby 1.8.7 patchlevel 249) (2010-07-26 49cf9ce) (Java HotSpot(T M) 64-Bit Server VM 1.6.0_21) [amd64-java] 0

          People

          • Assignee:
            Unassigned
            Reporter:
            Stéphane Boulanger
          • Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: