× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.



Alan,

That code is wrong, it is passing only one parameter to the RPG program, not the whole list.

And, it's not really necessary to do this... you can just use regular RPG parameters and skip the C stub, it's not doing anything for you but adding complexity.

True, the parameters you get will be null-terminated, but so what... the way you're passing the C parameter across, it'll still be null-terminated. RPG can easily copy it to a variable without the null terminator with it's %str() BIF.

You seem to be going out of your way to make this more complicated than it needs to be.

The complex part is really in the program that's calling spawn(). Don't forget to keep track of the pid and call wait() or waitpid() to clean up the child job! Don't forget to set up the inheritance and handle the proper signals! Don't forget to make null-terminated pointer arrays for args and envvars...

Or use SBMJOB instead.

-SK

On 5/26/2016 10:51 AM, Alan Campin wrote:
One other thing I forgot to mention is that spawn jobs need a C type
interface so you need a small stub of code to receive the parameters C
style and call an RPG procedure. .

#include <stdio.h>
#include <stdlib.h>

void RunWorker(char *);

main(int argc, char **argv) {
// Call RPG/ILE function to run worker job.
RunWorker(argv[1]); // Pass pointer to argument list.
}

* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
* RunWorker
* Run the Worker Job for the Iseries Interface.
* Input - Null Terminated List of parameters.
* Output - None
* Returns - None
* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
dcl-proc RunWorker Export;
dcl-pi *N;
InArgumentList Pointer Value;
end-pi;



On Thu, May 26, 2016 at 7:16 AM, Alan Campin <alan0307d@xxxxxxxxx> wrote:

Alex, normally you would not be using spawn to run jobs in QBATCH. Spawn
is used to connect to pre-start jobs.

You define a subsystem with pre-start jobs and then you use Spawn to take
over one of these jobs. This is not something that you would want to do in
QBATCH.

Having said that I have an open source project that I have been working
on. that consists of a socket server spawning socket worker jobs. One part
of that project is a service program XVSPWN that wraps up the spawn
interface to make it easy to use.

Could I know what you are planning to use the spawn api for. It sounds
like you might be looking for pre-start jobs.


On Thu, May 26, 2016 at 3:34 AM, Scott Klement <rpg400-l@xxxxxxxxxxxxxxxx>
wrote:

Hello Alex,

On 5/26/2016 2:09 AM, amunra@xxxxxx wrote:

Speaking about not CL technique.
Does anybody use spawn() API to create a separate jobs?
Some years ago I tried to use it, but I didn't find the way to
create job
in different subsystems.
Does anyone know if there is a way to run jobs in QBATCH subsystem?



I use the spawn() API quite often. But it is important to understand
that it does not simply submit a new job -- instead it creates a "child
process". Your job that calls spawn() is considered it's parent.

Due to the nature of a child process, it must always be in the same
subsystem as the parent job. So spawn() cannot cause a job to run in a
different subsystem.

There are other things about child processes that are different, too...
for example, even after the child process ends, some memory from it is kept
around until the parent process calls wait or waitpid to get it's exit
status, etc. Also, child processes inherit a number of things from the
parent. For details on all these things, see the manual for spawn() in the
IBM Knowledge Center.

For what you are doing, you might consider using the SBMJOB command
instead of the spawn() API.

-SK

--
This is the RPG programming on the IBM i (AS/400 and iSeries) (RPG400-L)
mailing list
To post a message email: RPG400-L@xxxxxxxxxxxx
To subscribe, unsubscribe, or change list options,
visit: http://lists.midrange.com/mailman/listinfo/rpg400-l
or email: RPG400-L-request@xxxxxxxxxxxx
Before posting, please take a moment to review the archives
at http://archive.midrange.com/rpg400-l.

Please contact support@xxxxxxxxxxxx for any subscription related
questions.




As an Amazon Associate we earn from qualifying purchases.

This thread ...

Follow-Ups:
Replies:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.