0
$\begingroup$

I use MathLink to call Mathematica from C program. After any opening to Mathematica, I do close the connection. However, I don't know why some connections are still there. I've been debugging for days but couldn't find the point.

Thus, I want to ask if there is any way to close all connection before I open the new one? Seems like not an optimal solution but for now its ok for me.

Thanks,

$\endgroup$
1
$\begingroup$

Try:

LinkClose[#] & /@ Links[]; 

It maps the list of all Links (Links[]) through LinkClose

$\endgroup$
6
  • $\begingroup$ Sorry, how to do it from C? $\endgroup$
    – Loi.Luu
    Nov 13 '13 at 14:55
  • $\begingroup$ @Loi.Luu how about sending an MLPutFunction with an EvaluatePacket containing Quit[] to close your kernel? page 29 edenwaith.com/development/tutorials/mathlink/ML_Tut.pdf $\endgroup$
    – PlaysDice
    Nov 13 '13 at 15:29
  • 1
    $\begingroup$ I want to close other connections which are supposed to be closed already. To close the current connection, I call the MLPutFunction(lp, Exit, 0L); statement. $\endgroup$
    – Loi.Luu
    Nov 13 '13 at 15:34
  • $\begingroup$ @Loi.Luu good point. Is a 'simple' way to use MLPutFunction to get MMA to do a variant of the LinkClose map (above), but not drop the current Link ? $\endgroup$
    – PlaysDice
    Nov 13 '13 at 15:43
  • 1
    $\begingroup$ @Loi.Luu. As written, yes, in MMA it closes all open 'Links' (incl JLinks etc). You may have to figure out whether the kernel can only close Links that are open to it (i.e not 'zombie' links left from other kernels) and how to specify the 'Link' you need to retain. If the one you need to preserve is the last 'Link' you could make the command 'LinkClose[#]&/@Drop[Links[],-1]' i.e 'LinkClose' the list of all 'Links' but omit the last one $\endgroup$
    – PlaysDice
    Nov 13 '13 at 16:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.