On Sunday 18 December 2005 12:09 am, James Edward Gray II wrote:
> On Dec 17, 2005, at 10:56 PM, Steve Litt wrote:
> > I want to translate it to Ruby, but I can't find an equivalent
> > to Perl's setsid anywhere in the Kernel module.
>
> I believe you are looking for Process.setsid.
>
>    ri Process.setsid
>
> James Edward Gray II

Thanks James.

That works! I can run it from a terminal, close the terminal, and 
the spawned program containues running. This is the exact behavior 
I need. However...

I have one other problem. Somehow I cannot use exec on my array of 
arguments -- only on the very first one (the program name). This 
means I can't pass arguments to the spawned program.

See here:

#!/usr/bin/ruby -w


def launch(argarray) 
	unless (fork) 
		Process::setsid    # set child process to new session
		unless (fork)      # Create a grandchild
			STDIN.close    # close std files
			STDOUT.close
			STDERR.close
			#exec argarray  ## This doesn't run the program
			command = argarray.shift
			exec command
			# exec command, argarray ## Doesn't run pgm
			# exec command, argarray[0], argarray[1]  ## no run pgm
		end
	end
	sleep(1)
end # launch()

launch(ARGV)