home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.sources.misc
- From: gs4t@virginia.edu (Gnanasekaran Swaminathan)
- Subject: v33i080: nhup - another nohup program, Part01/01
- Message-ID: <1992Nov19.032017.27360@sparky.imd.sterling.com>
- X-Md4-Signature: 8efdf55646b08d17a32d31cb5c6522f5
- Date: Thu, 19 Nov 1992 03:20:17 GMT
- Approved: kent@sparky.imd.sterling.com
-
- Submitted-by: gs4t@virginia.edu (Gnanasekaran Swaminathan)
- Posting-number: Volume 33, Issue 80
- Archive-name: nhup/part01
- Environment: UNIX
-
- nhup executes the command with the given arguments
- in the background and returns immediately without
- waiting for the command to complete. Also, the
- process executing the command is immune to hangup
- (HUP) and quit (QUIT) signals.
-
- Unlike nohup, nhup does not redirect the stdout
- and the stderr of the command to nohup.out file.
- Instead, it leaves the option to the user. If the
- user fails to specify any, the stdout and the std-
- err are redirected to /dev/null.
- ----------
- #! /bin/sh
- # This is a shell archive. Remove anything before this line, then feed it
- # into a shell via "sh file" or similar. To overwrite existing files,
- # type "sh file -c".
- # Contents: Makefile nhup.c
- # Wrapped by kent@sparky on Wed Nov 18 21:14:48 1992
- PATH=/bin:/usr/bin:/usr/ucb:/usr/local/bin:/usr/lbin ; export PATH
- echo If this archive is complete, you will see the following message:
- echo ' "shar: End of archive."'
- if test -f 'Makefile' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'Makefile'\"
- else
- echo shar: Extracting \"'Makefile'\" \(79 characters\)
- sed "s/^X//" >'Makefile' <<'END_OF_FILE'
- XCC=gcc
- X
- X
- Xnhup: nhup.c
- X $(CC) -o nhup nhup.c
- X
- Xinstall: nhup
- X cp nhup /bin/nhup
- END_OF_FILE
- if test 79 -ne `wc -c <'Makefile'`; then
- echo shar: \"'Makefile'\" unpacked with wrong size!
- fi
- # end of 'Makefile'
- fi
- if test -f 'nhup.c' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'nhup.c'\"
- else
- echo shar: Extracting \"'nhup.c'\" \(1644 characters\)
- sed "s/^X//" >'nhup.c' <<'END_OF_FILE'
- X/*
- X NAME
- X nhup -- run a command immune to hangups and quits.
- X
- X SYNOPSIS
- X nhup command [ arguments ]
- X
- X DESCRIPTION
- X nhup executes the command with the given arguments
- X in the background and returns immediately without
- X waiting for the command to complete. Also, the
- X process executing the command is immune to hangup
- X (HUP) and quit (QUIT) signals.
- X
- X Unlike nohup, nhup does not redirect the stdout
- X and the stderr of the command to nohup.out file.
- X Instead, it leaves the option to the user. If the
- X user fails to specify any, the stdout and the std-
- X err are redirected to /dev/null.
- X
- X EXAMPLES
- X % nhup prog1 | prog2
- X Run prog1 and pipe its output to prog2 and re-
- X direct the stderr of prog1 to /dev/null.
- X
- X % nhup prog1 > test 2> testerr
- X Run prog1 by directing its stdout to test and its
- X stderr to testerr.
- X
- X % nhup prog1
- X Run prog1 by directing its stdout and its stderr
- X to /dev/null
- X
- X SEE ALSO
- X nohup(1), signal(3)
- X
- X BUGS
- X Send them to Gnanasekaran Swaminathan <gs4t@virginia.edu>
- X*/
- X
- X#include <unistd.h>
- X#include <fcntl.h>
- X#include <stdio.h>
- X#include <stdlib.h>
- X#include <sys/signal.h>
- X
- Xstatic void error(const char* a1) { perror(a1); exit(1); }
- X
- Xint main(int ac, char** av)
- X{
- X int p = fork();
- X if (p == -1)
- X error(av[0]);
- X if (p == 0) {
- X /* child process */
- X int fd = open("/dev/null", O_WRONLY);
- X
- X signal(SIGHUP, SIG_IGN);
- X signal(SIGQUIT, SIG_IGN);
- X
- X if ( isatty(STDOUT_FILENO) && dup2(fd, STDOUT_FILENO) == -1 )
- X error(av[0]);
- X if ( isatty(STDERR_FILENO) && dup2(fd, STDERR_FILENO) == -1 )
- X error(av[0]);
- X
- X execvp(av[1], av+1);
- X error(av[1]);
- X }
- X return 0;
- X}
- X
- X
- END_OF_FILE
- if test 1644 -ne `wc -c <'nhup.c'`; then
- echo shar: \"'nhup.c'\" unpacked with wrong size!
- fi
- # end of 'nhup.c'
- fi
- echo shar: End of archive.
- exit 0
- exit 0 # Just in case...
-