[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: How to run in background through forking in Lua?
- From: Steve Litt <slitt@...>
- Date: Mon, 3 Jan 2011 08:42:19 -0500
Hi all,
My UMENU program (perl version) can run a program in the background like this:
./ufork.pl command_to_be_run_in_background
Here's the code of ufork.pl:
=======================================
#!/usr/bin/perl -w
use strict;
use POSIX qw(setsid);
sub launch(@) {
my(@args) = @_;
unless (fork) {
setsid; # set child process to new session
unless (fork) { # Create a grandchild
close STDIN; # close std files
close STDOUT;
close STDERR;
exec @args; # exec the x program
}
}
sleep(1);
}
launch(@ARGV);
=======================================
In my Lua readings I haven't come across a fork() command. Is there a way I
can rewrite my ufork.pl in Lua? If not, is there a different way to do it in
Lua? If not that, I spoze I could do it in C and make sure it's statically
compiled so as to be distributable as a binary.
Anyway, anyone know how to do this in Lua?
Thanks
SteveT
--
Steve Litt
Recession Relief Package
http://www.recession-relief.US
Twitter: http://www.twitter.com/stevelitt