KxSystems / kdb

Companion files to kdb+ and q
https://code.kx.com/q
Apache License 2.0
417 stars 163 forks source link

interfacing with C on linux problem #11

Closed Ch33m0 closed 5 years ago

Ch33m0 commented 5 years ago

Hello,

I am trying to access kdb+ from within C code on a Linux (CentOS) machine, and have followed the instructions outlined in this document:

https://code.kx.com/q/wp/c_api_for_kdb.pdf

The C code I`m using is like the one of page 4, just a simple khp/khpu to communicate with the port I set for q to listen on. (One difference is I'm using a slightly different compile command than given in that document, which is this: gcc -m32 -D KXVER=3 test.c c.o -o test -lpthread)

I can compile my test.c code and it will run but gets stuck on the line calling the khp function. I have checked my system to see which ports are listening, and everytime I run my code it adds one byte to my RECV-Q (I take this to mean the receiving queue) on that port. It would seem as though kdb won't accept what's being communicated to it. Everything seems fine on the surface, I am getting no errors, but I am simply stuck here.

Anyone know what might be causing this block in communication? Thank you

sv commented 5 years ago

Would you be able to provide a reproducer? C code as well as which version of kdb, how you start it and if any of handlers are redefined?

sv commented 5 years ago

You can get help quicker on our google group - https://groups.google.com/forum/?nomobile=true#!forum/personal-kdbplus

Ch33m0 commented 5 years ago

Oh yes, I figured out the issue in the end! I was making a rookie mistake. Essentially I was opening up an instance of q, telling it to listen on a port, then just pressing ctrl-z to return to the bash terminal. This was keeping the q process alive, but sleeping it so it couldn't actually respond to communications. How I fixed this was to go to the folder where I run q and type : [$nohup ./q -p 5001 &] , and then press enter once. After this I was able to run my c code perfectly fine and all the outgoing q messages were handled as expected. Sorry to bother, many resources seem to omit details that can get a beginner caught up in some confusion