          # File lib/eventmachine.rb, line 1341
    1341:   def self.watch_process(pid, handler=nil, *args)
    1342:     pid = pid.to_i
    1343:
    1344:     klass = if (handler and handler.is_a?(Class))
    1345:       raise ArgumentError, 'must provide module or subclass of EventMachine::ProcessWatch' unless ProcessWatch > handler
    1346:       handler
    1347:     else
    1348:       Class.new( ProcessWatch ) {handler and include handler}
    1349:     end
    1350:
    1351:     arity = klass.instance_method(:initialize).arity
    1352:     expected = arity >= 0 ? arity : -(arity + 1)
    1353:     if (arity >= 0 and args.size != expected) or (arity < 0 and args.size < expected)
    1354:       raise ArgumentError, "wrong number of arguments for #{klass}#initialize (#{args.size} for #{expected})"
    1355:     end
    1356:
    1357:     s = EM::watch_pid(pid)
    1358:     c = klass.new s, *args
    1359:     # we have to set the path like this because of how Connection.new works
    1360:     c.instance_variable_set("@pid", pid)
    1361:     @conns[s] = c
    1362:     block_given? and yield c
    1363:     c
    1364:   end