LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 06-02-2008, 06:16 AM   #1
Brad.Scalio@noaa.gov
Member
 
Registered: Jan 2007
Location: Washington DC
Distribution: RedHat & spins ... Fedora, CentOS, Mandriva
Posts: 82

Rep: Reputation: 15
Closing file descriptor for sshd that spawns remote threads


Greetings


I have a script that executes a remote secure shell to a server and runs a few startup scripts to launch in-house software. The scripts spawn various procs/threads so subsequently they inherit the shell's file descriptors...so the ssh session will hang as sshd is waiting for a close() it will never receive.

I can narrow down the PPID of the open fd's quite easily:
lsof -a -p `ps -ef|grep "\[priv\]" | grep -v grep | awk '{print $2}'` -d0,1,2

Unfortunately, I tried to redefine the fd inside the script and then close those before reassigning fd0,1,2 again, but it still hangs...I can always grep and | awk '{print $2}' for a string to get the PID to kill of the sshd but this could possibly return the wrong session should another sshd be open for the same grep string (which is slightly possible on the system)

Anyway, is there a good or standard way to close the fd for such an event? namely, an ssh to re remote server that executes a startup of various procs...or is there a good way to redefine the fd inside the script.

Thanks
 
Old 06-02-2008, 07:06 AM   #2
pinniped
Senior Member
 
Registered: May 2008
Location: planet earth
Distribution: Debian
Posts: 1,732

Rep: Reputation: 50
Can you write a dummy script that any of us can run to demonstrate the problem?
 
Old 06-02-2008, 09:11 AM   #3
Brad.Scalio@noaa.gov
Member
 
Registered: Jan 2007
Location: Washington DC
Distribution: RedHat & spins ... Fedora, CentOS, Mandriva
Posts: 82

Original Poster
Rep: Reputation: 15
It is similar, if not identical, to Bug52 in bugzilla, namely try the following:

From a host ssh to a client
Run any command that forks a process in the backgroun
Logout of client, ssh hangs


Similarly, shopt -s nohuponexit is one solution, however it doesn't work for me here. I also tried to export a PROMPT_COMMAND for "disown -a -h" but still no go. Finally, the only solution that works, which is a hack at best, is to kill -9 on the sshd that executes, but I wanted a more graceful way to get around this. Also, upgrading to a newer version of OpenSSH isn't a solution either (CM system).

I know there has been a lot of chatter on the web on these issues, but alas, no one had a solution, so figured I would give it a whirl here...
 
Old 06-02-2008, 12:56 PM   #4
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,415
Blog Entries: 55

Rep: Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600
How about not running the commands from SSH but it activating an 'at' job containing those commands?
 
  


Reply



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
Get the absolute path of file using file descriptor. appas Programming 7 01-19-2012 11:47 AM
Delay in closing threads pixellany LQ Suggestions & Feedback 2 04-27-2008 10:42 AM
Starting sshd: /etc/init.d/sshd: line 113: /usr/sbin/sshd: Permission denied sumanc Linux - Server 5 03-28-2008 04:59 AM
Closing/deleting threads dubya LQ Suggestions & Feedback 38 06-19-2006 02:42 AM
apt-file returns nothing; 'bad file descriptor' overbored Debian 3 10-03-2004 09:13 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 08:16 PM.

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
Open Source Consulting | Domain Registration