Solved

Kill the ftp process !

Posted on 1997-12-01
11
1,212 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
 
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
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 
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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
GIF file bit manipulation for color change 5 104
Add content to output file 4 58
EvenOdd challenge 10 83
Sed question 2 49
In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
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.
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

760 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now