Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

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,

share|improve this question
add comment

1 Answer

Try:

LinkClose[#] & /@ Links[]; 

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

share|improve this answer
    
Sorry, how to do it from C? –  Loi.Luu Nov 13 '13 at 14:55
    
@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 –  PlaysDice Nov 13 '13 at 15:29
1  
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. –  Loi.Luu Nov 13 '13 at 15:34
    
@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 ? –  PlaysDice Nov 13 '13 at 15:43
1  
@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 –  PlaysDice Nov 13 '13 at 16:45
show 1 more comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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