Solved

Kill the ftp process !

Posted on 1997-12-01
11
1,226 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
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 
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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
bobThere java chalenge 45 94
Error on moodle after upgrade 3 140
Prevent this page from creating additional dialogs. 3 622
fix34  challenge 9 143
This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
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.
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

828 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