From: peter@nmti.com (Peter da Silva)
Subject: Re: Spawn OSF commands from C?...
Date: Thu, 23 Mar 1995 18:33:52 GMT [thread overview]
Message-ID: <id.Q2EI1.JF5@nmti.com> (raw)
In-Reply-To: 1995Mar22.142836.15049@govonca.gov.on.ca
In article <1995Mar22.142836.15049@govonca.gov.on.ca>,
Teresa Wawrzyczek <wawrzyt@govonca.gov.on.ca> wrote:
> Can anyone tell me please if it is possible to spawn OSF commands from C
> and how to do that?
Easiest:
system(command);
Eg: system("ls -l");
Most control:
#define I_FAILED some failure value you want to use 1..255
int pid;
int status;
void *intval;
intval = signal(SIGINT, SIG_IGN); /* ignore ^C while child is running */
/* add other signals here */
switch(pid = fork()) { /* create a child process */
case -1: /* an error occurred, no child exists */
perror("fork"); /* tell the user */
return I_FAILED; /* tell the rest of the program */
case 0: /* This is the side of the fork in the child */
signal(SIGINT, intval); /* let child handle sigs */
execlp("command", "command_name", "arg1", ..., (char *)NULL);
perror("command"); /* If you got here, something's wrong */
exit(I_FAILED); /* Tell the parent */
default: /* This is the side of the fork in the parent */
waitpid(pid, &status, 0); /* wait for the child to die */
signal(SIGINT, intval); /* listen to our own signals */
return status;
}
Read the man pages for the various routines until you understand what this
code does. It's really quite a clever mechanism.
--
Peter da Silva `-_-'
Network Management Technology Incorporated 'U`
1601 Industrial Blvd. Sugar Land, TX 77478 USA
+1 713 274 5180 "Hast du Heute schon deinen Wolf umarmt?"
next prev parent reply other threads:[~1995-03-23 18:33 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
1995-03-22 14:28 Spawn OSF commands from C? Teresa Wawrzyczek
1995-03-23 18:33 ` Peter da Silva [this message]
1995-03-23 19:02 ` Greg Wooledge
1995-04-04 4:00 ` "Mark Jeffery"
read-only archive
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox