Hi,
Is there way to find a job id, of just started application in S*BASIC?
I was thinking of using NXJOB TK2 function, I probably need to walk throught the job tree, but not sure how to code it.
E.g.
100 ex mdv1_myjob
110 let myid = NXJOB (0,0)
Many thanks
Tom
JOB ID
Re: JOB ID
Tom,
actually, it's not very easy to do that from SuperBASIC, even if the QDOS trap does directly return the new job id, none of the S*Basic extensions I know will return the new job ID.
Some stuff you could be trying:
do a
jobs #x
ex myprogram
job #y
where x and y are pipes. Then read the pipes into string variables and spot the differences.
You can also PEEK the SV_JBTAG system variable that gives you the current highest job tag and scan for that tag in the JOBS output as above.
But both methods are likely to fail if any other job starts a new job just between your S*Basic program issuing the EX and the JOBS command
Tobias
actually, it's not very easy to do that from SuperBASIC, even if the QDOS trap does directly return the new job id, none of the S*Basic extensions I know will return the new job ID.
Some stuff you could be trying:
do a
jobs #x
ex myprogram
job #y
where x and y are pipes. Then read the pipes into string variables and spot the differences.
You can also PEEK the SV_JBTAG system variable that gives you the current highest job tag and scan for that tag in the JOBS output as above.
But both methods are likely to fail if any other job starts a new job just between your S*Basic program issuing the EX and the JOBS command
Tobias
ʎɐqǝ ɯoɹɟ ǝq oʇ ƃuᴉoƃ ʇou sᴉ pɹɐoqʎǝʞ ʇxǝu ʎɯ 'ɹɐǝp ɥO
Re: JOB ID
It might be better to approach this in a different way.
If using SBASIC, there are a number of other ways of finding the job id using a different approach.
1. Use the JOBID function:
id = JOBID(job_number,job_tag)
id = JOBID('Jobname')
id = JOBID this version allows a job to get its own ID.
This is useful for commands such as using HOME_DIR to check the home directory for a named job, e.g. check from SBASIC what is the home directory currently being used by Launchpad?
directory$=HOME_DIR$(JOBID("Launchpad"))
There are some commands in SBASIC which let you do various things once you now the JOB ID of a given job, e.g. SP_JOBOWNPAL and the SEND_EVENT keywords if jobs are communicating by events.
2. Use the FEX or EXF functions if the calling job (e.g. SBASIC) needs to know the ID of a job it is starting, e.g. if it wishes to communicate with it:
job_id = FEX("filename")
or
job_id = EXF("filename")
(I don't think there's any difference between the two, IIRC EXF was added to SBASIC when it was realised there was a FileInfo II keyword called FEX). There is a FEP function too which is to the EXEP command what FEX is to EX, i.e. can handle Things too.
Not quite what you were thinking of, I think, but might be useful if your software can work in this way.
If using SBASIC, there are a number of other ways of finding the job id using a different approach.
1. Use the JOBID function:
id = JOBID(job_number,job_tag)
id = JOBID('Jobname')
id = JOBID this version allows a job to get its own ID.
This is useful for commands such as using HOME_DIR to check the home directory for a named job, e.g. check from SBASIC what is the home directory currently being used by Launchpad?
directory$=HOME_DIR$(JOBID("Launchpad"))
There are some commands in SBASIC which let you do various things once you now the JOB ID of a given job, e.g. SP_JOBOWNPAL and the SEND_EVENT keywords if jobs are communicating by events.
2. Use the FEX or EXF functions if the calling job (e.g. SBASIC) needs to know the ID of a job it is starting, e.g. if it wishes to communicate with it:
job_id = FEX("filename")
or
job_id = EXF("filename")
(I don't think there's any difference between the two, IIRC EXF was added to SBASIC when it was realised there was a FileInfo II keyword called FEX). There is a FEP function too which is to the EXEP command what FEX is to EX, i.e. can handle Things too.
Not quite what you were thinking of, I think, but might be useful if your software can work in this way.
--
All things QL - https://dilwyn.theqlforum.com
All things QL - https://dilwyn.theqlforum.com
Re: JOB ID
Dilwyn,
thanks for mentioning FEX, that completely escaped me. That's the only way to actually be sure you hit the right job in a multi-tasking environment. It's however only available in SMSQ/E, to my knowledge (i.e not in any toolkit for the "standard" QL, which I guess Tom uses)
Tom,
NXJOB is definitely not the way to go. This is intended to walk the job tree and produca a listing like JOBS does.
Tobias
thanks for mentioning FEX, that completely escaped me. That's the only way to actually be sure you hit the right job in a multi-tasking environment. It's however only available in SMSQ/E, to my knowledge (i.e not in any toolkit for the "standard" QL, which I guess Tom uses)
Tom,
NXJOB is definitely not the way to go. This is intended to walk the job tree and produca a listing like JOBS does.
Tobias
ʎɐqǝ ɯoɹɟ ǝq oʇ ƃuᴉoƃ ʇou sᴉ pɹɐoqʎǝʞ ʇxǝu ʎɯ 'ɹɐǝp ɥO
Re: JOB ID
If it is the 'most recent' job you want it is the one with the highest 'tag' (see example below). If you are looking for a specific job you could search for it by name (modify the code below accordingly). If you want to execute a job and get that particular job's ID, then FEX is the best way to go - but that, as has been pointed out, is only available in SMSQ/E for now. EX/FEX has one 'issue': It creates independent jobs, ie owned by job 0. This is not always convenient for reasons those who need it will know. Therefore Ive added FEX_M to SMSQ/E. It should be out with the next release, whenever that will be. Jobs started with EX_M/FEX_M are owned by the calling job but unlike EW/FEW control immediately returns to the calling job.
100 PRINT 'Most recent job:'! JOB$(MRJ)
110 :
120 DEFine FuNction MRJ
130 LOCal n, tag, nj, n, ltg, jid
140 n = 0: tag = -1
150 REPeat nj
160 n = NXJOB(n, 0)
170 IF n = 0: EXIT nj
180 ltg = n DIV 65536
190 IF ltg > tag: tag = ltg: jid = n
200 END REPeat nj
210 RETurn jid
220 END DEFine MRJ
230 :
100 PRINT 'Most recent job:'! JOB$(MRJ)
110 :
120 DEFine FuNction MRJ
130 LOCal n, tag, nj, n, ltg, jid
140 n = 0: tag = -1
150 REPeat nj
160 n = NXJOB(n, 0)
170 IF n = 0: EXIT nj
180 ltg = n DIV 65536
190 IF ltg > tag: tag = ltg: jid = n
200 END REPeat nj
210 RETurn jid
220 END DEFine MRJ
230 :
Per
I love long walks, especially when they are taken by people who annoy me.
- Fred Allen
I love long walks, especially when they are taken by people who annoy me.
- Fred Allen
Re: JOB ID
Hi PJW,
This looks good.
My understanding of the code is, the tag id is always increased by 1, so looking for the highest tag, will get the most recent job id, right?
Many thanks
Tom
This looks good.
My understanding of the code is, the tag id is always increased by 1, so looking for the highest tag, will get the most recent job id, right?
Many thanks
Tom
Re: JOB ID
Tom,
Right. A qdos job Id consists of two components, the Id and the tag - the id is an index into the job table and thus re-used over time. To make a job Id unique, the ever-increased tag is added. The current highest tag is held in the above system variable.
Tobias
Right. A qdos job Id consists of two components, the Id and the tag - the id is an index into the job table and thus re-used over time. To make a job Id unique, the ever-increased tag is added. The current highest tag is held in the above system variable.
Tobias
ʎɐqǝ ɯoɹɟ ǝq oʇ ƃuᴉoƃ ʇou sᴉ pɹɐoqʎǝʞ ʇxǝu ʎɯ 'ɹɐǝp ɥO
Re: JOB ID
Yes, it was the most recently started job about 1/50th of a second ago! Ie, if you want the most recent job because you started it to control it in some way, it is not a sure-fire way to do it. Some other process could conceivably start another job between you activating your job and getting its handle - leaving you with the wrong handle. The pukka way to do it is to get the job's ID at the moment of creation. It is not difficult to setup and activate a job in such a way in assembler, but if you want to emulate the fancy parameter work that the EX/EW family do, that is pretty demanding. Of course a double check, on the name as well as the tag, is as good as certain too, so should be safe.
Per
I love long walks, especially when they are taken by people who annoy me.
- Fred Allen
I love long walks, especially when they are taken by people who annoy me.
- Fred Allen
Re: JOB ID
I decided to put my money where my mouth is (- or should that be my foot where my mouth is?) and devise a "safe" work-around for the problem I believe you presented. If this was not the problem, apologies. It was the problem for me recently, until I solved it in another way, hence my interest.
This seems to work. The job may of course be removed between getting its ID and using it, therefore the SPJOB and RJOB commands should have been error trapped, and work-arounds must be devised.
100 EXEC 'ram1_mylittlejob_exe'
110 jid = MRJ('My Little Job'): IF jid = 0: ERT -2
120 SPJOB jid, 1: REMark Fiddle with it
130 :
140 REMark Stuff goes on here..
150 :
160 RJOB jid, 0: REMark Finished with it
170 :
180 DEFine FuNction MRJ(n$)
190 LOCal n, tag, nj, n, ltg, jid
200 :
210 n = 0: tag = -1
220 REPeat nj
230 n = NXJOB(n, 0)
240 IF n = 0: EXIT nj
250 IF NOT JOB$(n) == n$: NEXT nj
260 ltg = n DIV 65536
270 IF ltg > tag: tag = ltg: jid = n
280 END REPeat nj
290 RETurn jid
300 END DEFine MRJ
This seems to work. The job may of course be removed between getting its ID and using it, therefore the SPJOB and RJOB commands should have been error trapped, and work-arounds must be devised.
100 EXEC 'ram1_mylittlejob_exe'
110 jid = MRJ('My Little Job'): IF jid = 0: ERT -2
120 SPJOB jid, 1: REMark Fiddle with it
130 :
140 REMark Stuff goes on here..
150 :
160 RJOB jid, 0: REMark Finished with it
170 :
180 DEFine FuNction MRJ(n$)
190 LOCal n, tag, nj, n, ltg, jid
200 :
210 n = 0: tag = -1
220 REPeat nj
230 n = NXJOB(n, 0)
240 IF n = 0: EXIT nj
250 IF NOT JOB$(n) == n$: NEXT nj
260 ltg = n DIV 65536
270 IF ltg > tag: tag = ltg: jid = n
280 END REPeat nj
290 RETurn jid
300 END DEFine MRJ
Per
I love long walks, especially when they are taken by people who annoy me.
- Fred Allen
I love long walks, especially when they are taken by people who annoy me.
- Fred Allen