Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game. |
Notices |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
 |
09-29-2004, 10:14 PM
|
#1
|
LQ Newbie
Registered: Sep 2004
Posts: 1
Rep:
|
Need to kill process 48 hours old
I need to get a script or learn how to make one that will tell me:
1. what emacs processes are running
2. kill the processes that are over 48 hours old.
in addition a little cron help would be nice. I want to have this process email me with what it killed when its done.
TIA
Captn Z
|
|
|
09-30-2004, 12:51 AM
|
#2
|
Member
Registered: Sep 2004
Location: New Zealand
Distribution: Debian
Posts: 900
Rep:
|
Try this at the command line:
Code:
ps -eo "%p %t %c" | grep emacs | grep "-" | grep -v " 1-"
If that successfully displays emacs sessions that have been running over two days, you should be able to do this:
Code:
#!/bin/bash
for x in `ps -eo "%p %t %c" | grep emacs | grep "-" | grep -v " 1-" | cut -c 1-5`; do
echo Killing process: `ps -p $x -o "%p %a"`
kill -9 $x
done
|
|
|
09-30-2004, 12:54 AM
|
#3
|
Member
Registered: Aug 2004
Location: Israel
Distribution: LMDE 5
Posts: 271
Rep:
|
As root do
You get a list of processes running on your machine.To kill one hit K,it asks you about PID(process' number).Enter a number,hit enter,then 9,enter.Process killed.Hit Q to leave.
|
|
|
09-30-2004, 02:06 AM
|
#4
|
Senior Member
Registered: Nov 2002
Location: CA
Distribution: redhat 7.3
Posts: 1,440
Rep:
|
Hi Cro,
I ran that with mine and get an output of:
132 9-03:45:15 emacs.
Can you explain what "9-03:45:15" means? Looks like 3 hours, 45 mins, and 15 seconds but what is the 9-? Thanks...
-twantrd
|
|
|
09-30-2004, 02:38 AM
|
#5
|
Member
Registered: Sep 2004
Distribution: Debian, Ubuntu, BeatrIX, OpenWRT
Posts: 273
Rep:
|
Nine days (plus three hours, forty-five minutes and 15 seconds)
(Gee - didn't know ps could do all that - you just made my day - thanks :-)
Groetjes,
Kees-Jan
|
|
|
09-30-2004, 03:07 AM
|
#6
|
Member
Registered: Sep 2004
Location: New Zealand
Distribution: Debian
Posts: 900
Rep:
|
Yeah, that was what I thought it was, but my server has a process with 42483-02:00:00 listed, and I haven't even had the server running that long, so I just had to check the ps source code to make sure... and it seems that's what it should be. My 42000 day process is some kind of anomaly 
|
|
|
All times are GMT -5. The time now is 03:15 AM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|