Operating System - HP-UX
1825808 Members
2261 Online
109688 Solutions
New Discussion

How to list currently running batch jobs

 
SOLVED
Go to solution
Richard Mertz
Regular Advisor

How to list currently running batch jobs

Can I list currently running jobs that were initiated via the batch command?

eg. Scriptfile testit:
---
while true
do
sleep 77
done
---
Run script with:
batch
at -l does not list running job. Is there a way to list it?
What anybody thinks of me is none of my business.
11 REPLIES 11
Frank Slootweg
Honored Contributor

Re: How to list currently running batch jobs

I do not know of a simple method.

I think the only thing you can do is extract and process these kind of entries from /var/adm/cron/log:

Start:

> CMD: 1042193129.b
> franks 8815 b Fri Jan 10 11:05:29 MET 2003
[...]

End:
< franks 8815 b Fri Jan 10 11:08:02 MET 2003
Chris Wilshaw
Honored Contributor

Re: How to list currently running batch jobs

Have you tried

at -l -qb

This tells is to use queue b, which should be those submitted via batch
U.SivaKumar_2
Honored Contributor

Re: How to list currently running batch jobs

Hi,

Try this.

#ps -ef | grep sleep

will show you whether your job is running or not.

regards,
U.SivaKumar
Innovations are made when conventions are broken
Armin Feller
Honored Contributor

Re: How to list currently running batch jobs

Hi,

I'm in mind with Frank. I found following documentation:

--- snip ---
Going through the source for at and cron and also looking at the manuals I found out the at jobs are place in /usr/spool/cron/atjobs (cronjobs for cron). Then cron monitors the entries and executes the jobs at appropriate time. The user can look at /usr/lib/cron/log file to monitor the log file and get process IDs. The log file keeps growing until the system is rebooted.
--- snap ---

Regards ...
Armin
Chris Wilshaw
Honored Contributor
Solution

Re: How to list currently running batch jobs

There is another way.

Find out the PID of your cron, and run a

ps -ef | grep

As cron is the parent process of the batch jobs, this should display them.
Richard Mertz
Regular Advisor

Re: How to list currently running batch jobs

Since the script produces no output, there is nothing stored in any of the suggested directories. at -l -qb does not display anything. The only thing that seems to be available is to ps -ef|grep /usr/sbin/cron,
grab the pid for cron and do a ps -ef for that pid which will show the processes that have been spawned by cron.
What anybody thinks of me is none of my business.
Carlos Fernandez Riera
Honored Contributor

Re: How to list currently running batch jobs


From /sbin/init.d/cron

'stop')
#
# Determine PID of process(es) to stop
#
pid=`ps -el | awk '( ($NF ~ /cron/) && ($4 != mypid) && ($5 != mypid) ){ print $4 }' mypid=$$ `
if [ "X$pid" != "X" ]; then
if kill $pid; then
echo "cron stopped"
else
set_return
echo "Unable to stop cron"
fi
fi
;;


A better solution could be:

ps -fg $pid will list all jobs started by any job started by cron.



unsupported
Pete Randall
Outstanding Contributor

Re: How to list currently running batch jobs

Since $pid doesn't exist, try:

ps -fg `ps -el | awk '( ($NF ~ /cron/) && ($4 != mypid) && ($5 !=mypid) ){ print $4 }' mypid=$$ `



Pete

Pete
Carlos Fernandez Riera
Honored Contributor

Re: How to list currently running batch jobs

Pete:

pid=`ps .....
unsupported
Pete Randall
Outstanding Contributor

Re: How to list currently running batch jobs

Of course you're right, Carlos, but, since I didn't see pid being set up in your post, I was trying to make things clear.

Pete

Pete
Carlos Fernandez Riera
Honored Contributor

Re: How to list currently running batch jobs

No problem Pete. I just copy it because:

1- The system check it this way.

2- what an an amazing syntax. Today is a good day too to learn somthing more.
unsupported