-2

How would I write a script that terminates all processes owned by the current user whose machine time (TIME column in ps output, which I believe is the CPU time) is greater than 1 minute?

4
  • 4
    What about init process? May 14 at 18:20
  • 1
    Is that 1 minute of cpu time or 1 minute from when the process started? For example sleep 90 will consume almost no cpu time, but will run for more than a minute. In general you probably want to run ps with a custom output format and then parse that output, maybe with awk to select the processes and then feed that to kill.
    – icarus
    May 14 at 18:57
  • 1
    @RomeoNinov Indeed, what about itself ? May 14 at 21:17
  • If on GNU/Linux, try ps xhopid,times | awk '$2 > 60 {print $1}' | xargs -r kill May 17 at 16:10

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.