Cancel process running for more than 5 days

Hello Group,

We want to create a script in order to filter process in the system with more than five days (STIME) and then kill them under Solaris 10.

How can we filter these kind of process ?

ps -efa 

Thanks in advance for your help

I would suspect that you need more than you are specifying. If you clobber every old process you will damage/crash the running system. How do we discriminate between old good ones vs old bad ones?

Hello Jim.

We have identify specially some printer process "lp -c" so now we have to filter using the parameter of five days. But we do not have clear how to list process by date.

I'm fairly sure Solaris 10 has the /proc filesystem so you should be able to look at the ctime of the /proc/<pid> directory.

You should be able to verify this for yourself by picking a long running process and examine the output of ls -ld eg:

# ls -ld /proc/5536
dr-xr-xr-x. 9 httpd httpd 0 Aug 14 22:54 /proc/5536
1 Like

Pure Posix / quite portable is

ps -e -o pid= -o etime= -o args=

The etime has the further advantage that it is already the difference current_date - stime.
For example

ps -e -o pid= -o etime= -o args= |
  while read pid etime args
  do
    case $args in
    *lp -c* )
      case $etime in
      5-* | [0-9][0-9]*-* )
        echo kill "$pid"
      ;;
      esac
    ;;
    esac
  done
1 Like