* Spawn OSF commands from C?...
@ 1995-03-22 14:28 Teresa Wawrzyczek
1995-03-23 18:33 ` Peter da Silva
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Teresa Wawrzyczek @ 1995-03-22 14:28 UTC (permalink / raw)
Hi!
Can anyone tell me please if it is possible to spawn OSF commands from C
and how to do that?
Thank you
--
Teresa Wawrzyczek
Ministry of Natural Resources
wawrzyt@mnr.gov.on.ca
^ permalink raw reply [flat|nested] 4+ messages in thread* Re: Spawn OSF commands from C?... 1995-03-22 14:28 Spawn OSF commands from C? Teresa Wawrzyczek @ 1995-03-23 18:33 ` Peter da Silva 1995-03-23 19:02 ` Greg Wooledge 1995-04-04 4:00 ` "Mark Jeffery" 2 siblings, 0 replies; 4+ messages in thread From: Peter da Silva @ 1995-03-23 18:33 UTC (permalink / raw) 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?" ^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Spawn OSF commands from C?... 1995-03-22 14:28 Spawn OSF commands from C? Teresa Wawrzyczek 1995-03-23 18:33 ` Peter da Silva @ 1995-03-23 19:02 ` Greg Wooledge 1995-04-04 4:00 ` "Mark Jeffery" 2 siblings, 0 replies; 4+ messages in thread From: Greg Wooledge @ 1995-03-23 19:02 UTC (permalink / raw) wawrzyt@govonca.gov.on.ca (Teresa Wawrzyczek) writes: >Can anyone tell me please if it is possible to spawn OSF commands from C >and how to do that? #include <stdlib.h> system("command"); Please read the FAQ files for these three(!) groups, and your C book. -- # Greg Wooledge /..\ # bh43@summitis.com \--/ Have a day. # aa1254@freenet.lorain.oberlin.edu (good luck) ^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Spawn OSF commands from C?... 1995-03-22 14:28 Spawn OSF commands from C? Teresa Wawrzyczek 1995-03-23 18:33 ` Peter da Silva 1995-03-23 19:02 ` Greg Wooledge @ 1995-04-04 4:00 ` "Mark Jeffery" 2 siblings, 0 replies; 4+ messages in thread From: "Mark Jeffery" @ 1995-04-04 4:00 UTC (permalink / raw) fork, and exec! For example: #include <stdio.h> main() { if (fork() == 0) { execve("ls","/bin/ls","-l",NULL); } else { printf("I've forked to create a child, running ls\n"); } } This is probably not right, but if you do a man fork, and a man exec, then it will help you. Mark. ^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~1995-04-04 4:00 UTC | newest] Thread overview: 4+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 1995-03-22 14:28 Spawn OSF commands from C? Teresa Wawrzyczek 1995-03-23 18:33 ` Peter da Silva 1995-03-23 19:02 ` Greg Wooledge 1995-04-04 4:00 ` "Mark Jeffery"
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox