Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

EXPECT: Killing spawned processes

810 views
Skip to first unread message

ar...@vina-tech.com

unread,
Mar 4, 1998, 3:00:00 AM3/4/98
to

I spawn a series of ftp processes. Basically I ftp, do a get, quit, ftp,
do a get, quit, repeat indefinitely. Unfortunately, I end up with a series
of zombie ftp processes. These processes appear to hang on to pty resources,
and thus I eventually run out. Does anybody know how I might be able to
terminate these zombie processes?

[arnel@arnel ~]$ ps | grep ftp
2122 p1 I+ 0:00.54 /usr/local/bin/expect ./ftprun
2129 p5- Z 0:00.00 (ftp)
2148 p7- Z 0:00.00 (ftp)
2174 p8- Z 0:00.00 (ftp)
2191 p9- Z 0:00.00 (ftp)
2208 pa- Z 0:00.00 (ftp)

>couldn't fork child process: resource temporarily unavailable

/\rnel
ar...@vina-tech.com

-----== Posted via Deja News, The Leader in Internet Discussion ==-----
http://www.dejanews.com/ Now offering spam-free web-based newsreading

Philip T. Kasiecki

unread,
Mar 5, 1998, 3:00:00 AM3/5/98
to

In article <6dkr42$ap0$1...@nnrp1.dejanews.com>, ar...@vina-tech.com wrote:
: I spawn a series of ftp processes. Basically I ftp, do a get, quit, ftp,

: do a get, quit, repeat indefinitely. Unfortunately, I end up with a series
: of zombie ftp processes. These processes appear to hang on to pty resources,
: and thus I eventually run out. Does anybody know how I might be able to
: terminate these zombie processes?

: [arnel@arnel ~]$ ps | grep ftp
: 2122 p1 I+ 0:00.54 /usr/local/bin/expect ./ftprun
: 2129 p5- Z 0:00.00 (ftp)
: 2148 p7- Z 0:00.00 (ftp)
: 2174 p8- Z 0:00.00 (ftp)
: 2191 p9- Z 0:00.00 (ftp)
: 2208 pa- Z 0:00.00 (ftp)

: >couldn't fork child process: resource temporarily unavailable

This comes down to knowing how processes are in UNIX. I'm no expert on
the matter, but from what I see in "UNIX Secrets" (James C. Armstrong, Jr.),
these can be killed through the use of the SIGCHLD signal, or by killing the
parent process(es) involved.
I'd suggest that you post this to one of the UNIX newsgroups, or check a
source on processes in UNIX. On my links page, I have a link to the UNIX
Reference Desk, as far as online resources go (simply go to the URL in my
.sig, then choose the last link on the list).

Phil Kasiecki

--
Philip T. Kasiecki
Hardware Co-op, Cognex Corporation
(508) 650-3308
pkas...@cognex.com
http://lynx.dac.neu.edu/home/httpd/p/pkasieck/

jim kraai

unread,
Mar 5, 1998, 3:00:00 AM3/5/98
to

On Wed, 04 Mar 1998 18:21:00 -0600, ar...@vina-tech.com wrote:

>I spawn a series of ftp processes. Basically I ftp, do a get, quit, ftp,
>do a get, quit, repeat indefinitely. Unfortunately, I end up with a series
>of zombie ftp processes. These processes appear to hang on to pty resources,
>and thus I eventually run out. Does anybody know how I might be able to
>terminate these zombie processes?

Easy answer--don't do it this way.
Don't spawn a new ftp session for each get,
use ftp's open & close commands.

I don't know how to kill off the orphaned processes, other than doing
an
after 10000
or something similar
(while {[exec ps -ef | grep $ftp_pid | wc -l] > 1} {
after 1000
}
to allow the OS to clean up the orphan.

The following code is untested, & you'll need to tune the
user/pass/mode stuff. There is NO error checking, either!

#!/usr/bin/wish

# Read in the (assumed) file of files
#
# Use url parsing magic to get a list of lists
# the sublists looking like:
# {host ?user? ?pass? mode dir/filespec}
#
# or skip the user/pass if it's anon/e-mail_addr

# spawn ftp (probably with a -i)
...

foreach file in $filelist {
# Open the connection
send "open [lindex $file 0]\r" ; expect "Name(.*): "

# Send username
send "[lindex $file 1]\r" ; expect "ssword:"

# Send password
send "[lindex $file 2]\r" ; expect "ftp>"

# change to desired file transfer mode
send "[lindex $file 3]\r" ; expect "ftp>"

# cd to the directory
send "cd [file dirname [lindex $file 3]]\r" ; expect "ftp>"

# get the file
send "get [lindex $file 4]\r" ; expect "ftp>"

# close the connection
send "close\r" ; expect "ftp>"
}

# cleanup code
bell ; bell ; bell
puts "Done!!!"


Don Libes

unread,
Mar 6, 1998, 3:00:00 AM3/6/98
to

In article <34feb753....@news.internetmci.com> pap...@plutonium.net (jim kraai) writes:
On Wed, 04 Mar 1998 18:21:00 -0600, ar...@vina-tech.com wrote:
>I spawn a series of ftp processes. Basically I ftp, do a get, quit, ftp,
>do a get, quit, repeat indefinitely. Unfortunately, I end up with a series
>of zombie ftp processes. These processes appear to hang on to pty resources,
>and thus I eventually run out. Does anybody know how I might be able to
>terminate these zombie processes?

Expect keeps the connection open until you explicitly indicate you're
through with it. Read about close/wait in the documentation.

Don

0 new messages