Sha256: d4c9817756d2ddf035cffb064d74056aae8ede9305c2a599657611d8ec2a8a1e

Contents?: true

Size: 895 Bytes

Versions: 2

Compression:

Stored size: 895 Bytes

Contents

module Pione
  module Command
    class ChildProcess < FrontOwnerCommand
      use_option_module CommandOption::ChildProcessOption
      attr_reader :parent_front

      # @api private
      def validate_options
        if not(@no_parent_mode) and @parent_front.nil?
          abort("option error: no caller front address")
        end
      end

      # @api private
      def prepare
        super

        # "ppid == 1" means the parent is dead
        terminater = Proc.new do
          if Process.ppid == 1
            abort
            terminate
          end
          sleep 3
        end

        # watch that the parent process exists
        @watchdog = Agent::TrivialRoutineWorker.new(terminater)
      end

      # @api private
      def start
        @watchdog.start
      end

      def terminate
        @watchdog.terminate
        super
        abort
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
pione-0.1.1 lib/pione/command/child-process.rb
pione-0.1.0 lib/pione/command/child-process.rb