Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game. |
Notices |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
|
04-24-2006, 11:06 AM
|
#1
|
Member
Registered: Aug 2004
Location: The Netherlands
Distribution: RedHat 2, 3, 4, 5, Fedora, SuSE, Gentoo
Posts: 372
Rep:
|
ssh -> perl -> spawn background proces hangs ssh session
Hi,
I have a back-up policy that logs into machines to run a perl script. This script runs processes like database listeners or apachectl processes.
These processes do daemonize, but they get stuck attached to the logon terminal, making ssh to hang on exit. You'll have to break the process to regain control of the tty (or interactively, use '\n~.' to terminate the ssh session).
On bash scripting, the solution mostly is redirection of input / output, like: 'apachectl </dev/null &>/dev/null'.
In perl, however, this doesn't seem to work..
Any of you who has experienced this before and know of a solution to this?? I can't seem to be able to find a proper solution to this.
Thanks..
|
|
|
04-24-2006, 04:37 PM
|
#2
|
LQ Newbie
Registered: Mar 2005
Posts: 6
Rep:
|
Fragment of script that launches a "sticky" process:
#!/usr/bin/perl
<set up $script_file>
my $pid = fork;
if ($pid) {
my $pid_return = waitpid($pid,0);
my $fork_return = $? >> 8;
my $message = ($fork_return) ? "FAILED" : "SUCCESS";
print "Requested Fork ", $message, "\n";
exit $fork_return;
}
die "Could Not Fork: $!" unless defined($pid);
close STDIN;
close STDOUT;
close STDERR;
POSIX::setsid() or die "Could Not Start New Session: $!";
my $sys_return = system($script_file);
my $retcode = $sys_return >> 8;
exit $retcode;
|
|
|
04-25-2006, 02:05 AM
|
#3
|
Member
Registered: Aug 2004
Location: The Netherlands
Distribution: RedHat 2, 3, 4, 5, Fedora, SuSE, Gentoo
Posts: 372
Original Poster
Rep:
|
Thanks in advance! I will try this right away...
If it works... you've just made my day lol..
|
|
|
All times are GMT -5. The time now is 10:30 AM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|