Written by

Question Ruslan K · Jun 15, 2018

Kill process started by JOB

Can anybody give me a correct example to kill process started by JOB command?

Comments

Ruslan K  Jun 15, 2018 to GUILHERME CRUZ DA CUNHA

I meant programmatically

0
Filip Nys  Jun 18, 2018 to Ruslan K

Try this :

zn "%SYS"
SET ActiveJob=##CLASS(SYS.Process).%OpenId(Job)  // where Job is the processnumber
ActiveJob.Terminate()
ActiveJob.%Close()
 

0
Eduard Lebedyuk  Jun 18, 2018 to Filip Nys

While working, this solution has a drawback of working only in %SYS namespace.

0
Filip Nys  Jun 18, 2018 to Eduard Lebedyuk

Save first the original namespace where you are working

znspace=$znspace
Job=""
Do {
Job=....
Job'="",Job'=$j
{
zn "%SYS"
SET ActiveJob=##CLASS(SYS.Process).%OpenId(Job)
ActiveJob.Terminate()
ActiveJob.%Close()
h 1
ActiveJob
zn znspace
 

0
Eduard Lebedyuk  Jun 18, 2018 to Filip Nys

Solution from @Vitaliy Serdtsev is simpler and can be called from any namespace

do $SYSTEM.Process.Terminate()

Additionally user may not have access to %SYS namespace due to security reasons.

0
Filip Nys  Jun 18, 2018 to Eduard Lebedyuk

Indeed, but that option is not available in version 2012.2

0
Alexey Maslov  Jun 18, 2018 to Eduard Lebedyuk
do %SYSTEM.Process:Terminate()

I'm just curious: since which version this exotic form of call is supported?

In Caché 2015.1...2017.2 only traditional forms are possible, e.g.

do $SYSTEM.Process.Terminate(pid)
0
Eduard Lebedyuk  Jun 18, 2018 to Alexey Maslov

My bad,

do %SYSTEM.Process:Terminate(pid)

is invalid, only this form is correct:

do $SYSTEM.Process.Terminate(pid)

Fixed in original comment.

0
Edward Clark  Jul 2, 2018 to Filip Nys

When you need to switch namespaces, instead of saving the current namespace and then restoring it after, you can put the code into its own method or routine and use NEW $NAMESPACE, for example:

Method KillJob(job) { new $namespace s $namespace="%SYS" do whatever(job) }

and the original namespace will be restored when the method exits. I think this also works inside of an old-fashioned argumentless DO block.

0
Robert Cemper · Jun 15, 2018

Ruslan,

After execution, the JOB Command sets system variable $ZCHILD

$ZCHILD contains the ID of the last child process that the current process created with the JOB command. If your process has not used JOB to create a child process, $ZCHILD returns 0 (zero).

$ZCHILD being set does not mean that the job was successfully started. It only means that the process was created and the parameters were passed successfully.

Now you have the OIID in hands to apply to $System.Process.Terminate(bgjob) as suggested already by  Vitaliy Serdtsev

0