Script to get hung jobs in cron service.

Hi
I want to have a list of hung jobs in crontab .
e.g
The below output gives a list of hung jobs including the running one.

"

USER1] ps -ef | grep 22345
root 22345 1 0 Nov 10 ? 0:09 /usr/sbin/cron
user2 1061 22345 0 Nov 11 ? 0:00 sh -c /u01/user2s/b7111/movecsv.ksh
oracle 20456 29535 0 09:49:41 pts/5 0:00 grep 22345
oracle 3436 22345 0 05:00:01 ? 0:00 sh -c /d002/oracle/dbrun1.sh
oracle 19920 22345 0 00:01:00 ? 0:00 sh -c /d002/oracle/common/dbatools/alertscan.sh /d002/oracle/common/dbatools/al
user2 18201 22345 0 Nov 11 ? 0:00 sh -c /u01/user2s/b7111/movecsv.ksh
oracle 3400 22345 0 Nov 13 ? 0:00 sh -c /d002/oracle/dbrun2.sh
 

"
Now the output of the script should be as follows.

 
user UnixPorcess obName
---- ----------- -------
user2 1061 sh -c /u01/user2s/b7111/movecsv.ksh
user2 18201 sh -c /u01/user2s/b7111/movecsv.ksh
oracle 3400 sh -c /d002/oracle/dbrun2.sh

Can you please help me to write a shell script to get the required output.

So point to be noted here is output should not contain
"1) Today's job list, 2) grep command process(e.g 20456) and the process which is running from root user (root 22345)

Thanks in Advance.

ps -ef | 
awk -v d="$(date +"%b %d")" '/22345/ && !($0 ~ d) && !/grep/ && !/root/'

OK trick is to spot STIME column with the "Mth dd" format (and ignore hh:mm:ss).
I assigned cron process id (22345) to an awk var as I'd assume you are fetching this PID already in your script and would want to pass it to awk.

$ ps -ef | awk -v PP=22345 '$3==PP && $0 !~ "[0-9]:[0-9][0-9]:[0-9]" {
 printf $1" "$2 ;
 for(i=9;i<=NF;i++) printf " "$i;
 printf "\n"
}'
user2 1061 sh -c /u01/user2s/b7111/movecsv.ksh
user2 18201 sh -c /u01/user2s/b7111/movecsv.ksh
oracle 3400 sh -c /d002/oracle/dbrun2.sh