LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
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


Reply
  Search this Thread
Old 09-29-2004, 10:14 PM   #1
captnz
LQ Newbie
 
Registered: Sep 2004
Posts: 1

Rep: Reputation: 0
Question 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
 
Old 09-30-2004, 12:51 AM   #2
CroMagnon
Member
 
Registered: Sep 2004
Location: New Zealand
Distribution: Debian
Posts: 900

Rep: Reputation: 33
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
 
Old 09-30-2004, 12:54 AM   #3
z-vet
Member
 
Registered: Aug 2004
Location: Israel
Distribution: LMDE 5
Posts: 271

Rep: Reputation: 34
As root do
Code:
#top
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.
 
Old 09-30-2004, 02:06 AM   #4
twantrd
Senior Member
 
Registered: Nov 2002
Location: CA
Distribution: redhat 7.3
Posts: 1,440

Rep: Reputation: 52
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
 
Old 09-30-2004, 02:38 AM   #5
kees-jan
Member
 
Registered: Sep 2004
Distribution: Debian, Ubuntu, BeatrIX, OpenWRT
Posts: 273

Rep: Reputation: 30
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
 
Old 09-30-2004, 03:07 AM   #6
CroMagnon
Member
 
Registered: Sep 2004
Location: New Zealand
Distribution: Debian
Posts: 900

Rep: Reputation: 33
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
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Process won't kill mrsolo Linux - Software 5 08-03-2007 12:45 PM
cannot kill process (kill -9 does not work) mazer13a Linux - General 1 05-27-2005 02:32 PM
can't kill the process ust Linux - Software 2 12-16-2004 11:53 PM
how to kill a process in C++? mimithebrain Programming 9 06-17-2004 05:20 PM
How to kill a certain process? AMDPwred Linux - General 3 10-01-2002 01:40 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 03:15 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration