LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
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



Reply
 
Search this Thread
Old 04-24-2006, 11:06 AM   #1
rhoekstra
Member
 
Registered: Aug 2004
Location: The Netherlands
Distribution: RedHat 2, 3, 4, 5, Fedora, SuSE, Gentoo
Posts: 360

Rep: Reputation: 41
Question 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..
 
Old 04-24-2006, 04:37 PM   #2
Belenos
LQ Newbie
 
Registered: Mar 2005
Posts: 6

Rep: Reputation: 0
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;
 
Old 04-25-2006, 02:05 AM   #3
rhoekstra
Member
 
Registered: Aug 2004
Location: The Netherlands
Distribution: RedHat 2, 3, 4, 5, Fedora, SuSE, Gentoo
Posts: 360

Original Poster
Rep: Reputation: 41
Thanks in advance! I will try this right away...
If it works... you've just made my day lol..
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
ssh-agent, ssh-add and ssh-keygen AND CVS raylpc Linux - General 2 11-19-2008 03:50 AM
Mac OS X ssh client / linux sshd : ssh hangs/disconnects Apollo77 Linux - Networking 1 05-24-2006 12:53 PM
Passwordless SSH with SSH commercial server and open ssh cereal83 Linux - General 7 04-18-2006 01:34 PM
Running a program in the background - SSH ziggo0 Linux - Newbie 4 03-05-2005 02:30 PM
proces ssh and scp stopped, connection hangs prut Linux - Networking 2 04-10-2004 11:57 AM


All times are GMT -5. The time now is 12:54 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration