Kill process started by JOB

Primary tabs


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

  • 0
  • 2
  • 1,031
  • 12


Try this :

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

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

Save first the original namespace where you are working

Do {
zn "%SYS"
SET ActiveJob=##CLASS(SYS.Process).%OpenId(Job)
h 1
zn znspace

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.

Indeed, but that option is not available in version 2012.2

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)

My bad,

do %SYSTEM.Process:Terminate(pid)

is invalid, only this form is correct:

do $SYSTEM.Process.Terminate(pid)

Fixed in original comment.

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.


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