sketchucation logo sketchucation
    • Login
    🤑 SketchPlus 1.3 | 44 Tools for $15 until June 20th Buy Now

    Kill external process

    Scheduled Pinned Locked Moved Developers' Forum
    7 Posts 2 Posters 263 Views 2 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • M Offline
      maricanis
      last edited by

      Hi,

      I'm running some external processes from my plugin.
      Since they can run rather long, I would like to offer a user possibility to abort started external process. Is there some elegant way to do it in SU?

      Only way I've found for now is when user press some button, I call:

      taskkill /f /im my_program.exe
      

      or

      tskill my_program
      

      (since no idea how to get PID of the external process from my Plugin, I use image name or exectuable name).

      BTW: I'm running process with UI.openURL() and batch_file.
      I'm using SU 8 in Windows 7 operating system.

      Thanks in advance,
      Marija

      1 Reply Last reply Reply Quote 0
      • Dan RathbunD Offline
        Dan Rathbun
        last edited by

        You can use tlist.exe (XP) or tasklist.exe (Vista/Win7) to check when the SU process ended.

        (The catch is that XP Home doesn't come with tlist.exe, it must be ... installed separately*. It comes installed standard on XP Pro, or Win Server 2003+.

        • is referring to the separate "Support Tools" installer on the Windows install CD.

        And.. I do not know what the equivalent is on OSX.

        I'm not here much anymore.

        1 Reply Last reply Reply Quote 0
        • M Offline
          maricanis
          last edited by

          Thanks Dan,

          For now plugin is only Windows oriented so these tasklist or tlist would do the job for listing running processes

          1 Reply Last reply Reply Quote 0
          • M Offline
            maricanis
            last edited by

            Hi,

            I've implemented killing of external process (which is started by UI.openURL) with next method:
            -call 'tasklist' - to check is process is still running and to get process PID
            -then in plugin Process.kill("KILL",PID)

            This approach works, but I also want to inform object that started external process that process is killed (so some timers are stopped).
            I though to implement that with signals:
            -after process is killed I send signal "USR1" for example
            -and I trap the same signal in class that started process - and then stop timers.

            Problem is that Sketchup doesn't recognize "USR1" signal.

            I've tried in Ruby console:

            
            Signal.list.keys.join ", " 
            TERM, SEGV, KILL, EXIT, INT, FPE, ABRT, ILL
            
            

            But none of these signals are the ones I need, I need some custom user defined signal for my plugin.

            Is the thing I need possible, and how to do it in Ruby/Sketchup?

            Thanks in advance,
            Marija

            1 Reply Last reply Reply Quote 0
            • Dan RathbunD Offline
              Dan Rathbun
              last edited by

              Just pass a reference of the timer id object, to the method that kills the process, and call UI.stop_timer(tid) from that method, after it is verified, that the process is dead.

              I'm not here much anymore.

              1 Reply Last reply Reply Quote 0
              • Dan RathbunD Offline
                Dan Rathbun
                last edited by

                OR.. in object 1, write a callback method that is called from the killing object:

                def deceased
                  UI.stop_timer(@tid)
                  # any other post death cleanup
                end
                

                Assumes you save a reference to the timer id, in object 1, when you started the timer, like:
                @tid = UI.start_timer(delay,true) { # code block }

                I'm not here much anymore.

                1 Reply Last reply Reply Quote 0
                • M Offline
                  maricanis
                  last edited by

                  Thanks Dan,

                  Your suggestion to write callback that is called from killing object, was very useful idea - and makes nice readable code.

                  Much better idea then various signals I planned to use before.

                  Thanks again,
                  Marija

                  1 Reply Last reply Reply Quote 0
                  • 1 / 1
                  • First post
                    Last post
                  Buy SketchPlus
                  Buy SUbD
                  Buy WrapR
                  Buy eBook
                  Buy Modelur
                  Buy Vertex Tools
                  Buy SketchCuisine
                  Buy FormFonts

                  Advertisement