Solved

Kill the ftp process !

Posted on 1997-12-01
11
1,230 Views
Last Modified: 2013-12-26
I want to have a sh shell script to kill all the ftp process which have run for more than 2 hrs. I can find out those ftp process by using ps -ef | grep ^ftp
Also, I am not a super user, so I need a way to test it
0
Comment
Question by:clo1
11 Comments
 
LVL 2

Expert Comment

by:df020797
ID: 1295716
There is no way in shell scripts checking the run time of a process, only idle time.
0
 
LVL 84

Expert Comment

by:ozo
ID: 1295717
#!/bin/csh
set p = `ps | grep ftp`
echo run time of process is $p[3]

0
 
LVL 2

Expert Comment

by:df020797
ID: 1295718
Thats the idletime, not runtime,
set p=`ps -ef| grep sched`
echo $p[3]
-> 0

Now... I dont think shed has run for 0 time units ;-) Its a BIT to important for the system. The machines uptime is months. Yes, I used a Sys V, Solaris, but it wouldnt do any difference if I use ps -ef on a BSDish ps... still is the idle time in $p[3] cuz I tried this with /usr/ucb/ps.

set p=`/usr/ucb/ps -ef`
echo $p[3]
-> 0.00

So my answer is still... runtime cant be accessed through ps ina  shell.

0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 84

Expert Comment

by:ozo
ID: 1295719
#!/bin/sh
P=`ps | grep ftp`
T=`echo $P | cut -f3 -d' ' -`
echo run time of process is $T

0
 
LVL 2

Expert Comment

by:df020797
ID: 1295720
This I yield to... on a Sys V, not BSD. Cuz then it shows accumulated CPU time. So I back up.

(it didnt work with BSDish ps, but with Sys V ps).
0
 
LVL 84

Expert Comment

by:ozo
ID: 1295721
I didn't say -ef, since I thought that might be more system dependent,
but on my system  
set p=`/usr/ucb/ps -ef`
echo $p[3]
is PPID
$p[7] or $p[8] would be run time,
(depending on how many fields STIME took)

0
 
LVL 2

Expert Comment

by:df020797
ID: 1295722
Yapp... hence this discussion as coming to a "prestige" level, I took time to read the man files ;-)

I was though certain runtime wasnt in a ps listing, cause normally only ideltime is of interest. Then I suddenly knew where I got that erroneous idea from... w.

So, you deserve the points :-)
Hope clo1 realizes that.

Thanks for an interesting discussion, it sure lightened up my afternoon.
0
 
LVL 2

Author Comment

by:clo1
ID: 1295723
All I want is just check the time, if it is more than two hrs, so I need to kill this process.
0
 
LVL 84

Expert Comment

by:ozo
ID: 1295724
If you really want to check run time, and not elapsed time or idle time, you might do something like:
#!/bin/sh
F=`ps -ef | grep ftp`
while test -n "$P"
do
T=`echo $P | cut -f3 -d' ' -`
if test $T -gt 120
then
PID=`echo $P | cut -f1 -d' ' -`
kill $PID
fi
P=`echo $P |  cut -f 5- -d' '`
done

0
 
LVL 1

Expert Comment

by:dhughes111797
ID: 1295725
On Solaris, Column 5 of ps output is STIME - starting time
of the process. (If you have another OS, your mileage may vary,
but it should be documented in the man page). You can
compare the STIME to the current time. If it's more than 2 hours,
you can kill it.
How to test? start a bunch of ftps to a remote site. Let them
sit there. run your script. It'll kill them because the processes are yours
0
 

Accepted Solution

by:
mikal120797 earned 50 total points
ID: 1295726
I am not sure there is a neat way to do this. It would probably be easier to write a simple program which returns the wall time of the named process. You could then use this program's output to work out which processes to kill.

The program would be placed in a for loop, would be handed each process id, and then you would look at the individual answers returned.

In fact, you don't even have to write the code for this program, Stevens includes it in Advanced Programming in the UNIX environment... The source code for this book is available at: ftp.uu.net in published/books/stevens.advprog.tar.Z the program is in section 8.15.

Is this any help?
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
unable to delete all specified values regedit 38 718
has77  challenge 9 98
Window placement 17 95
NotAlone Challenge 20 88
Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

749 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question