*BSD News Article 74423


Return to BSD News archive

Path: euryale.cc.adfa.oz.au!newshost.anu.edu.au!harbinger.cc.monash.edu.au!munnari.OZ.AU!spool.mu.edu!howland.reston.ans.net!Germany.EU.net!main.Germany.EU.net!Dortmund.Germany.EU.net!interface-business.de!usenet
From: j@ida.interface-business.de (J Wunsch)
Newsgroups: comp.unix.bsd.misc,comp.unix.aix
Subject: Re: Executing process from child process
Date: 22 Jul 1996 09:15:27 GMT
Organization: interface business GmbH, Dresden
Lines: 38
Message-ID: <4svgrf$3gh@innocence.interface-business.de>
References: <31EEED83.1CB5@erinet.com>
Reply-To: joerg_wunsch@interface-business.de (Joerg Wunsch)
NNTP-Posting-Host: ida.interface-business.de
X-Newsreader: knews 0.9.6
X-Phone: +49-351-31809-14
X-Fax: +49-351-3361187
X-PGP-Fingerprint: DC 47 E6 E4 FF A6 E9 8F  93 21 E0 7D F9 12 D6 4E
Xref: euryale.cc.adfa.oz.au comp.unix.bsd.misc:1259 comp.unix.aix:81103

Gary Lynn Beckler <garyb@EriNet.com> wrote:

> Has anyone been successful executing a process using "execv" from 
> a forked child process?  I have been unsuccessful.  Basically, I have 
> client and server software running on separate machines.  After the 
> connection is made, the server process forks, and the spawned child 
> process calls "execv" with the proper arguments.  We are using 4.4BSD 
> and IBM AIX 3.0.
> 
> I would like to see sample code if possible.  Thanks in advance.

You must do something fundamentally wrong.

#include <stdio.h>
#include <unistd.h>

int
main(void)
{
	pid_t child;
	char *args[] = {"ls", "-l", ".", (char *)0};

	if ((child = fork()) == -1) {
		fprintf(stderr, "Cannot fork.\n");
		return 1;
	} else if (child) {
		execv("/bin/ls", args);
		fprintf(stderr, "Cannot execute /bin/ls.\n");
		return 1;
	} else
		printf("Hi, i'm the parent...\n");
	return 0;
}

-- 
J"org Wunsch					       Unix support engineer
joerg_wunsch@interface-business.de       http://www.interface-business.de/~j