Use more recommeded fork method in Perl script

This commit is contained in:
2025-12-20 22:16:16 -08:00
parent 869ebd595c
commit 334031dc70

View File

@@ -133,26 +133,23 @@ sub launch_program {
my ($app, @program) = @_; my ($app, @program) = @_;
my $prog = join(' ', @program); my $prog = join(' ', @program);
system("nohup $prog > /dev/null 2>&1 &"); my $launch_cmd = "nohup $prog > /dev/null 2>&1 &";
exit(0); my $pid = fork();
# my $pid = fork(); die "launch_program: couldn't fork: $!" unless defined $pid;
# die "launch_program: couldn't fork: $!" unless defined $pid; if ($pid == 0) {
# Child process
# Detach from the parent process's session to survive terminal closure
# (optional but recommended for complete daemonization)
# Use 'setsid()' if available/needed. A simple exit of the parent may suffice.
# if ($pid == 0) { # Execute the new program in place of the child process
# # Child process exec($launch_cmd) or die "Couldn't exec your program: $!";
# # Detach from the parent process's session to survive terminal closure } else {
# # (optional but recommended for complete daemonization) # Parent process
# # Use 'setsid()' if available/needed. A simple exit of the parent may suffice. # Parent can do other things here, or simply exit
exit(0); # Exit the parent script
# # Execute the new program in place of the child process }
# exec(@program) or die "Couldn't exec your program: $!";
# } else {
# # Parent process
# print "Launched child process with PID $pid\n";
# # Parent can do other things here, or simply exit
# exit(0); # Exit the parent script
# }
} }