aboutsummaryrefslogtreecommitdiff
path: root/src/mosflm.c
diff options
context:
space:
mode:
authorThomas White <taw@physics.org>2011-01-14 17:24:26 +0100
committerThomas White <taw@physics.org>2012-02-22 15:27:10 +0100
commit9d3389752cd074534f1d9e2576366c155b563206 (patch)
tree3302cea94e85e39d4f51384e4909692bdb245af3 /src/mosflm.c
parent356f2e554b9f0777eaa216684896a95a0d67b326 (diff)
Run MOSFLM in a subprocess to avoid blocking SIGCHLD
Diffstat (limited to 'src/mosflm.c')
-rw-r--r--src/mosflm.c29
1 files changed, 19 insertions, 10 deletions
diff --git a/src/mosflm.c b/src/mosflm.c
index 177ad87c..6cf29636 100644
--- a/src/mosflm.c
+++ b/src/mosflm.c
@@ -20,7 +20,9 @@
#include <stdio.h>
#include <math.h>
#include <string.h>
-
+#include <sys/types.h>
+#include <sys/wait.h>
+#include <unistd.h>
#include "image.h"
#include "mosflm.h"
@@ -29,7 +31,6 @@
#include "peaks.h"
-
/*
todo
@@ -230,6 +231,8 @@ void run_mosflm(struct image *image, UnitCell *cell)
double wavelength; /* angstrom */
char newmatfile[128];
int fail;
+ pid_t pid;
+ int r;
write_spt(image);
write_img(image); /* dummy image */
@@ -275,11 +278,21 @@ void run_mosflm(struct image *image, UnitCell *cell)
remove(newmatfile);
/* Run the mosflm script */
- fail = system(mos_cmd);
- if (fail) {
- ERROR("mosflm execution failed.\n");
- return;
+ pid = fork();
+ if ( !( (pid != 0) && (pid != -1) ) ) {
+ if ( pid == -1 ) {
+ ERROR("fork() failed.\n");
+ } else {
+
+ /* Forked successfully, child process */
+ if ( system(mos_cmd) ) {
+ ERROR("MOSFLM execution failed.\n");
+ return;
+ }
+
+ }
}
+ waitpid(pid, &r, 0);
/* Read the mosflm NEWMAT file and set cell candidate */
/* Existence of this file means possible success. Pretty shady. */
@@ -288,8 +301,4 @@ void run_mosflm(struct image *image, UnitCell *cell)
printf("Failed to read mosflm NEWMAT file.\n");
return;
}
-
-
-
- return;
}