Showing results for 
Search instead for 
Did you mean: 

startup script for multiprocess q (correction to previous)

New Contributor III

Hi All,

I'm trying to start up kdb with multiple processes to use to write scripts with KDB developer. I understand that the processes that are set up need to be done so outside of the master process.

I have attempted to do this with a function in my .bashrc that creates 7 instances which are expecting a maximum of 8 processes. I then start up a final process with developer. When I do this and try to connect, my OS informs developer that the connections are refused. Could you advise on the correct way to start 8 processes to use with IPC in KDB? This is my multiple process startup function in .bashrc:

mq() { echo "Spawning 7 q processes"; q -s -8 -p 20001; q -s -8 -p 20002; q -s -8 -p 20003; q -s -8 -p 20004; q -s -8 -p 20005; q -s -8 -p 20006; q -s -8 -p 20007; }

This is the code in .bashrc to start developer:

# Assumes user name is claude and opens Q with 8 threads. (to build separate processes use a negative number) alias q='rlwrap -r q -s -8' # Developer set to open with 8 threads. (to build separate processes use a negative number) alias developer='source /pathToDir/developer/config/config.profile; rlwrap -r q /pathToDir/developer/launcher.q_'

This appears to work with each process loading scripts and printing success (so 7 results).

To start all this up, I open one terminal and type mq then open another terminal and type developer . Once in developer, I assign a handle to each process like this: 

{hopen("::",string[20000+x])}each 1+til 7 

Then the system tells me that the connection is refused.

How should I do this?

Thanks and regards,




New Contributor

I attempted to start up multiple processes using the .bashrc command, and I get the same "connection refused" message when I attempt to assign a handle to each process. It seems as if the first one (on 20001) starts up just fine, but the rest do not as they depends on the previous process being closed. Closing 20001 then opens 20002, closing 20002 opens 20003 and so on.   

I was able to get separate q processes up and running by separating each line with '&' rather than a semicolon since the processes need to start up in the background:

{ echo "Spawning 7 q processes"; q -s -8 -p 2001 & q -s -8 -p 2002 & q -s -8 -p 2003 & q -s -8 -p 2004 & q -s -8 -p 2005 & q -s -8 -p 2006 & q -s -8 -p 2007; }

Using the same command to open the handles should execute without any issues. 


You need to start up the q processes in the background. The function is currently running the first one, if the q session exits then the next will run, and so on so forth.

function mq() {
    echo "Spawning 7 q processes"
    for port in 20001 20002 20003 20004 20005 20006 20007; do
        cmd="/home/alvi/q64/l64/q -p $port > /dev/null 2>&1 &"
        echo $cmd
        eval $cmd

Thanks Alvi - this worked!
FYI for anybody who follows - also when you use .z.w on a secondary process, it will report your process not it's own - so don't sweat it if all your secondaries have the same .z.w. Also, you need to manually allocated processes to be used in Peach using .z.pd .