Solved

Kill the ftp process !

Posted on 1997-12-01
11
1,238 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Get proactive database performance tuning online

At Percona’s web store you can order full Percona Database Performance Audit in minutes. Find out the health of your database, and how to improve it. Pay online with a credit card. Improve your database performance now!

 
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: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying 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

Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
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.
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…

623 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