Sha256: 2d4a3a942a403946b9be7f06a874a1fa8250872016fbdda025a4523810901734

Contents?: true

Size: 1.01 KB

Versions: 1

Compression:

Stored size: 1.01 KB

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

      # Terminate the child front. Kill watchdog.
      #
      # @return [void]
      def terminate
        # kill watchdog
        @watchdog.terminate
        # go to other termination processes
        super
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
pione-0.1.2 lib/pione/command/child-process.rb