question about using G_system command
Michael Shapiro
shapiro at zorro.cecer.army.mil
Fri Jul 31 14:53:49 EDT 1992
What Unix box are you using? I have never known G_system() to fail before.
Perhaps they way the system() call has to be implemented on your platform
differs from the way other version of Unix do it? Here is the G_system()
call. As far as I can tell it should be identical to the way system()
is implemented except for the signal handling (which is added).
/****************************************************************/
#include <signal.h>
#include <stdio.h>
G_system (command)
char *command;
{
int status, pid, w;
void (*sigint)(), (*sigquit)() ; /* new */
sigint = signal (SIGINT, SIG_IGN); /* new */
sigquit = signal (SIGQUIT, SIG_IGN); /* new */
fflush (stdout);
fflush (stderr);
if ( (pid = fork()) == 0)
{
signal (SIGINT, SIG_DFL); /* new */
signal (SIGQUIT, SIG_DFL); /* new */
execl ("/bin/sh", "sh", "-c", command, 0);
_exit(127);
}
if (pid < 0)
{
fprintf (stderr, "WARNING: can not create a new process\n");
status = -1;
}
else
{
while ( (w = wait (&status)) != pid && w != -1)
;
if (w == -1)
status = -1;
}
signal (SIGINT, sigint); /* new */
signal (SIGQUIT, sigquit); /* new */
return (status);
}
|
|
|I am trying to use G_system command to fork a process or to call
|an external module. It does not seem to work. However if I use system call
|it does work. Any one can explain why it is doing?
|
|Thanks.
|
|Srinivasan.
|srin at brcsun1.tamu.edu
|
|
-----------------------------------------------------------------
Michael Shapiro U.S. Army CERL
email: shapiro at zorro.cecer.army.mil Environmental Division
phone: (217) 352-6511 ext 526 P.O. Box 9005
fax: (217) 373-7222 Champaign, Ill. 61826-9005
-----------------------------------------------------------------
More information about the grass-dev
mailing list