Usenet comp.sys.dec (1990-2013)
 help / color / mirror / Atom feed
From: Ron Natalie <ron@sensor.com>
Subject: Re: Something kills me (-9) on a ^Z
Date: 1997/07/16	[thread overview]
Message-ID: <33CCDABB.2C15@sensor.com> (raw)
In-Reply-To: 33CCD673.9CA@sensor.com

[-- Attachment #1: atest.c --]
[-- Type: text/plain, Size: 1242 bytes --]


#include <unistd.h>
#include <signal.h>

#define	FU_SUCCESS		0
#define FU_NULL_COMMAND		-1
#define FU_FORK_FAILS		-2
#define	FU_WAITPID_FAILS	-3

int
fork_unix(char *command, int *statloc)  {
    pid_t pid;
    int omask;
    void  (*intsave)(), (*quitsave)();

    if(!command) return FU_NULL_COMMAND;

#if SVR4_SIGNALS
    sighold(SIGCHLD);
#else
    omask = sigblock(sigmask(SIGCHLD));
#endif

    switch(pid = vfork()) {
    case -1:			/* error */
#if SVR4_SIGNALS
	sigrelse(SIGCHLD);
#else
	(void)sigsetmask(omask);
#endif
	return FU_FORK_FAILS;
    case 0:				/* child */
#if SVR4_SIGNALS
	sigrelse(SIGCHLD);
#else
	(void)sigsetmask(omask);
#endif
#if 0
	setsid();
#endif
	execl("/bin/sh", "sh", "-c", command, (char *)NULL);
	_exit(127);
    }
    intsave = signal(SIGINT, SIG_IGN);
    quitsave = signal(SIGQUIT, SIG_IGN);
    pid = waitpid(pid, (int *)statloc, 0);
#if SVR4_SIGNALS
    sigrelse(SIGINT);
    sigrelse(SIGQUIT);
    sigrelse(SIGHUP);
#else
    (void)sigsetmask(omask);
#endif
    (void)signal(SIGINT, intsave);
    (void)signal(SIGQUIT, quitsave);

    if(pid == -1)
	return FU_WAITPID_FAILS;
    else
	return FU_SUCCESS;
}



main() {
    int st;
    fork_unix("./x &", &st);

    while(1) {
	sleep(200);
    }
}




      reply	other threads:[~1997-07-16  4:00 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1997-07-15  4:00 Something kills me (-9) on a ^Z Ron Natalie
1997-07-16  4:00 ` Ron Natalie
1997-07-16  4:00   ` Ron Natalie [this message]
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