#!/bin/csh
set p = `ps | grep ftp`
echo run time of process is $p[3]
Main Topics
Browse All TopicsI 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
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
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.
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.
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
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.ad
Is this any help?
Business Accounts
Answer for Membership
by: dfPosted on 1997-12-02 at 04:12:20ID: 1295716
There is no way in shell scripts checking the run time of a process, only idle time.