From mboxrd@z Thu Jan 1 00:00:00 1970 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: fc89c,4c41e220f4b086f5 X-Google-Attributes: gidfc89c,public X-Google-Thread: fee84,4c41e220f4b086f5 X-Google-Attributes: gidfee84,public X-Google-Thread: 1014db,4c41e220f4b086f5 X-Google-Attributes: gid1014db,public X-Google-ArrivalTime: 1995-03-23 10:36:14 PST Newsgroups: comp.lang.c,comp.unix.programmer,comp.unix.osf.osf1 Path: nntp.gmd.de!news.rwth-aachen.de!news.rhrz.uni-bonn.de!news.uni-stuttgart.de!rz.uni-karlsruhe.de!xlink.net!howland.reston.ans.net!swrinde!news.uh.edu!uuneo.neosoft.com!nmtigw!peter From: peter@nmti.com (Peter da Silva) Subject: Re: Spawn OSF commands from C?... Message-ID: Sender: peter@nmti.com (peter da silva) Organization: Network/development platform support, NMTI References: <1995Mar22.142836.15049@govonca.gov.on.ca> Date: Thu, 23 Mar 1995 18:33:52 GMT Xref: nntp.gmd.de comp.lang.c:82362 comp.unix.programmer:23780 comp.unix.osf.osf1:8482 In article <1995Mar22.142836.15049@govonca.gov.on.ca>, Teresa Wawrzyczek 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?"