Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How to recognize ENDJOB *CNTRLD

465 views
Skip to first unread message

Klaus Moedinger

unread,
Jan 18, 2008, 2:36:27 PM1/18/08
to
Hello,

I've written a socket program in RPG. Most of the time, it is in state
SELW (socket select()).

I wrote and registered an exit handler, which is executed whenever the
call stack entry is terminated - like so:

0274.00 D goExitHandler S * PROCPTR
INZ(%PADDR(ExitHandler))
...
...
0304.00 * Register exit handler
0305.00 C CALLB 'CEERTX'
0306.00 C PARM goExitHandler
0307.00 C PARM *OMIT
0308.00 C PARM *OMIT

This works fine for SysReq 2 and ENDJOB *IMMED and I can do housekeeping
like closing sockets, streamfiles, whatever.

I would also like to be notified, whenever someone issues ENDJOB
*CNTRLD. I studied the ILE RPG Programming manual (condition handlers
and so forth), but I didn't get any further.

So my basic question is:
How can I register a procedure that gets called on ENDJOB *CNTRLD?

Thanks in advance for any hints and suggestions.

Best regards,
Klaus


Karl Hanson

unread,
Jan 18, 2008, 3:49:41 PM1/18/08
to
Klaus Moedinger wrote:
> Hello,
>
> I've written a socket program in RPG. Most of the time, it is in state
> SELW (socket select()).
>
> I wrote and registered an exit handler, which is executed whenever the
> call stack entry is terminated - like so:
>
<snip>

>
> This works fine for SysReq 2 and ENDJOB *IMMED and I can do housekeeping
> like closing sockets, streamfiles, whatever.
>
> I would also like to be notified, whenever someone issues ENDJOB
> *CNTRLD. I studied the ILE RPG Programming manual (condition handlers
> and so forth), but I didn't get any further.
>
> So my basic question is:
> How can I register a procedure that gets called on ENDJOB *CNTRLD?
>

There may be a way to register a program/procedure as you desire, or if
not, an alternative/equivalent mechanism. Hopefully others will show how
it's done. If not, this suggestion might be considered a last resort.
Reading the description of socket select(), I see a wait_time parameter.
This would seem to enable a polling technique, whereby whenever control
returns to the program from select(), the current job "end status" could
be retrieved and checked. A couple ways to retrieve it: use RTVJOBA
ENDSTS() in a CL program, or use the QUSRJOBI API.

(Note that if using ILE, a CL ILE module could be created and bound with
RPG in the same program, for better call/return performance.)

--
Karl Hanson

Klaus Moedinger

unread,
Jan 18, 2008, 4:24:39 PM1/18/08
to
Karl Hanson wrote:

[snip...]

>> So my basic question is:
>> How can I register a procedure that gets called on ENDJOB *CNTRLD?
>>

> There may be a way to register a program/procedure as you desire, or if
> not, an alternative/equivalent mechanism. Hopefully others will show how
> it's done. If not, this suggestion might be considered a last resort.
> Reading the description of socket select(), I see a wait_time parameter.
> This would seem to enable a polling technique, whereby whenever control
> returns to the program from select(), the current job "end status" could
> be retrieved and checked. A couple ways to retrieve it: use RTVJOBA
> ENDSTS() in a CL program, or use the QUSRJOBI API.
>
> (Note that if using ILE, a CL ILE module could be created and bound with
> RPG in the same program, for better call/return performance.)

Karl, many thanks for your help. My program is indeed written in ILE, it
already uses procedures implemented in other modules (RPG, C and CL).
I will give it a try.

Best regards and have a nice weekend,
Klaus


CRPence

unread,
Jan 18, 2008, 7:29:34 PM1/18/08
to
QUSRJOBI API JOBI0600 Format "End status" [and the more efficient key
0502 in QWCRTVCA API] gives the same capability as the RTVJOBA ENDSTS()
to determine if the job was requested to end in a controlled manner.
Using one of those between any transactions that run and before any
wait, in combination with wait timeouts on those functions that wait,
enables periodic polling within the job for an EndJob that was performed
against it. If that indication is missed by polling [or such polling is
simply omitted], then as I understand it, the exit handler should get
invoked to perform the cleanup when the actual immediate-end is effected
[after the allotted time runs out].

However rather than trying to handle generic ENDJOB OPTION(*CNTRLD)
DELAY(##) requests, there is at least one other perspective to consider.
Why not instead, ensure the system management for termination of that
application should be requested via an /application end request/. That
is, the application itself provides an interface to end its job, by some
command *other* than ENDJOB. For example, consider STRTCPSVR and
ENDTCPSVR. The application TCP server application is started and then
ended, not by ENDJOB, but by a specific command that requests to end
that application; the server which was started previously, also by a
command. The job can be requested by some notification broadcast to
that job, that it should /close up shop/ and end.

After writing this... I checked the docs to clarify my expectation of
the cancel handler, and there is actually a page that says much of the
same as I wrote above. Similar specifically to the paragraph just above
where I suggest creating something like an ENDMYAPP command, one part of
that doc suggests "you can remove your cancel handlers and create" such
a command. I do not agree with removing the handlers part; the code
will still want to handle EndRqs, error cases, and EndJob. Anyhow I see
it also mentions setting up a handler for SIGTERM to directly catch the
*CNTRLD end.

http://publib.boulder.ibm.com/infocenter/iseries/v5r4/index.jsp?topic=/apis/concept7.htm

Regards, Chuck
--
All comments provided "as is" with no warranties of any kind
whatsoever and may not represent positions, strategies, nor views of my
employer

George Timms

unread,
Jan 18, 2008, 9:03:35 PM1/18/08
to
"Klaus Moedinger" <klaus.m...@web.de> wrote in message
news:fmqv3p$30i$02$1...@news.t-online.com...

> I would also like to be notified, whenever someone issues ENDJOB *CNTRLD.
> I studied the ILE RPG Programming manual (condition handlers and so
> forth), but I didn't get any further.
>
> So my basic question is:
> How can I register a procedure that gets called on ENDJOB *CNTRLD?

This excerpt from
http://publib.boulder.ibm.com/infocenter/iseries/v5r4/index.jsp?topic=/cl/endjob.htm
shows that you can define an ILE signal handler (at least in v5r4; I don't
know about earlier releases):

Specifies whether the job ends immediately or in a controlled manner that
lets the application program perform end-of-job processing. In either case,
the system performs certain job cleanup processing.
*CNTRLD: The job ends in a controlled manner. This allows the program
running to perform cleanup (end-of-job processing). When a job being ended
has a signal handling procedure for the asynchronous signal SIGTERM, the
SIGTERM signal is generated for that job. The application has the amount of
time specified on the DELAY parameter to complete cleanup before the job is
ended.

--
George Timms
IBM Rochester


Barbara Morris

unread,
Jan 18, 2008, 9:48:38 PM1/18/08
to
Klaus Moedinger wrote:
> ...

> I would also like to be notified, whenever someone issues ENDJOB
> *CNTRLD. I studied the ILE RPG Programming manual (condition handlers
> and so forth), but I didn't get any further.
>
> So my basic question is:
> How can I register a procedure that gets called on ENDJOB *CNTRLD?
>

If you decide to use some polling mechanism (such as calling RTVJOBA),
RPG has the %SHTDN builtin function (or SHTDN opcode) that returns '1'
if the job or subsystem is ending controlled.

if %shtdn();
--- do any necessary cleanup
return;
endif;

Ken Sims

unread,
Jan 18, 2008, 11:25:45 PM1/18/08
to
Hi Karl -

On Fri, 18 Jan 2008 14:49:41 -0600, Karl Hanson
<kcha...@youess.ibm.com> wrote:

>This would seem to enable a polling technique, whereby whenever control
>returns to the program from select(), the current job "end status" could
>be retrieved and checked. A couple ways to retrieve it: use RTVJOBA
>ENDSTS() in a CL program, or use the QUSRJOBI API.
>
>(Note that if using ILE, a CL ILE module could be created and bound with
>RPG in the same program, for better call/return performance.)

How about the %shtdn BIF (or the SHDTN opcode)?

--
Ken
Opinions expressed are my own and do not necessarily represent the views
of my employer or anyone in their right mind.

Klaus Moedinger

unread,
Jan 19, 2008, 6:26:40 AM1/19/08
to
Hello,

wow, lots of helpful people here. :-) Thank you all. :-)

The "listen for SIGTERM" technique seems to do exactly what I want.

The suggestion to implement a command that connects to the socket server
and issues a shutdown request is also well worth considering.

Best regards
Klaus

0 new messages