Instrument Control (GPIB, Serial, VISA, IVI)

cancel
Showing results for 
Search instead for 
Did you mean: 

a combination between the ni488 library and system calls on debian 3.1 (sarge) causes segmentation fault

First of all, I know that the ni488.2 gpib library does not officially have support for debian. However, I tried my luck to see if it would actually work under Debian 3.1 (sarge) and it generally does -  except for one problem which can be illustrated with this short example:

#include <stdio.h>
#include <stdlib.h>
#include <ni488.h>
int main(void){

  SendIFC(0);

  system("ls");

return 0;
}

I am using a pci gpib card.

Compiled with: gcc-3.4 test.c -lgpibapi -o test.o
Executing ./test.o multiple times will result in either a successful system call to ls and the content of the working directory displayed or a segmentation fault - it seems to fail more times than it succeeds.

Then my question is whether you have seen this problem before?  And if there exist a general solution to the problem. I have found an ugly work-around to put the gpib card offline before the system call (ibonl(0,0)) and then online again afterwards. In  that case the problem does not occur.

I hope you have some suggestions for a solution.

Best regards
M.Sc.EE. Michael Skipper Andersen
Department of Antennas and Propogation
Institute of Electronic Systems
Aalborg University
Denmark
0 Kudos
Message 1 of 2
(3,133 Views)
Hello,
 
We have had some problems with the fork() command and an active NI-488.2 driver that are probably related to your issue.  I believe the system() call makes a fork() call to start the shell.  Unfortunately, at this time, there is no workaround other than avoiding fork-like calls or, as you discovered, being careful with the state of the GPIB driver as you perform the fork-like call.  Since system() probably ends the child process after it is done, I think that you're probably safe to continue using the NI-488.2 driver after the system() call.  If this were a fork() call, you may have issues making GPIB calls from the child process.
 
I hope to get this fixed in the next version of the NI-488.2 for Linux driver.  Unfortunately, I cannot provide a timeline for the next version.
 
Scott B.
GPIB Software
National Instruments
0 Kudos
Message 2 of 2
(3,120 Views)