Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to terminate a remote KDB+ session via script?

Tags:

kdb

I need to kill a remote KDB+ session. This can be done in several ways but I'd prefer to use IPC handlers.

I start a KDB+ session:

$ q -p 5000
KDB+ 3.0 2012.11.13 Copyright (C) 1993-2012 Kx Systems

Then I start another KDB session and I manage to kill the server successfully:

$ q
KDB+ 3.0 2012.11.13 Copyright (C) 1993-2012 Kx Systems

q)h: hopen `::5000
q)h(exit;0)
'close
q)\\

But, if I create a script (test.q) with the instructions above, it fails:

$ cat test.q 
h: hopen `::5000
h(exit;0)
\\

$ q test.q 
KDB+ 3.0 2012.11.13 Copyright (C) 1993-2012 Kx Systems

k){0N!x y}
'close
@
"q"
"h(exit;0)"
q))

Any ideas? I really appreciate.

like image 349
nunaxe Avatar asked Feb 04 '13 16:02

nunaxe


2 Answers

You are making a synchronous request to the remote server which means that you are expecting a response. The problem is that your request causes the remote server to shut down and close the connection immediately, resulting in an error and causing q to go into debug mode.

If you just want to send an exit to the remote server without causing an error, you can send the request asynchronously by using a negative value for the connection handle (notice the lack of the 'close error):

q)h: hopen `::5000
q)(neg h) (exit;0)
q)\\
like image 151
moepud Avatar answered Nov 10 '22 16:11

moepud


I managed to sort this out by using Protected Evaluation:

In test.q file:

h: hopen `::5000
@[h; "exit 0"; {}]
\\
like image 27
nunaxe Avatar answered Nov 10 '22 18:11

nunaxe