2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

ruby fork background

Last updated at Posted at 2016-11-07

fork combine daemon

a = 12

fork do
	Process.daemon(true,true)
	sleep 10
	puts Process.ppid
	puts a
	puts "lalalala"
end

fork do
	Process.daemon(true,true)
	sleep 5
	puts "gagagaga"
end

puts Process.pid
puts "quit"
require 'spawnling'

a = 12

Spawnling.new do
	# Process.daemon(true,true)
	sleep 10
	puts Process.ppid
	puts a
	puts "lalalala"
end

Spawnling.new do
	# Process.daemon(true,true)
	sleep 5
	puts "gagagaga"
end

puts Process.pid
puts "quit"
a = 12

job1 = fork do 
    # Process.daemon(true,true)
    sleep 10
    puts Process.ppid
    puts a
    puts "lalalala"
end

job2 = fork do
    # Process.daemon(true,true)
    sleep 5
    puts "gagagaga"
end

Process.detach(job1)
Process.detach(job2)
puts Process.pid
puts "quit"
2
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?