Class: Process::Group::Fork

Inherits:
Command
  • Object
show all
Defined in:
lib/process/group.rb

Overview

Runs a given block using a forked process.

Instance Attribute Summary

Attributes inherited from Command

#options, #pid

Instance Method Summary collapse

Methods inherited from Command

#foreground?, #kill

Constructor Details

#initialize(block, **options) ⇒ Fork

Returns a new instance of Fork.



78
79
80
81
82
# File 'lib/process/group.rb', line 78

def initialize(block, **options)
	@block = block
	
	super(**options)
end

Instance Method Details

#call(**options) ⇒ Object



84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# File 'lib/process/group.rb', line 84

def call(**options)
	options = @options.merge(options)
	
	@pid = Process.fork(&@block)
	
	if options[:pgroup] == true
		# Establishes the child process as a process group leader:
		Process.setpgid(@pid, 0)
	elsif pgroup = options[:pgroup]
		# Set this process as part of the existing process group:
		Process.setpgid(@pid, pgroup)
	end
	
	return @pid
end

#resume(*arguments) ⇒ Object



100
101
102
# File 'lib/process/group.rb', line 100

def resume(*arguments)
	@fiber.resume(*arguments)
end