Author:lamp
URL:http://www.brazilfw.com.br/users/AdslWiFi/otros/nohup.tgz
Add-on State: test
Add-on Version: 1.0
Original Project Version:http://www.opensource.apple.com/source/shell_cmds/shell_cmds-118/nohup/nohup.c
Original Project URL:Unknown
System Version Required: 2.31.10 o superior
Other Packages Required: none
Other Packages Conflict: Ninguno
Zize: 2.92KB
MD5: 4133C642E92F0E46FC1B87B13075D2DA
Descripcion:
http://dns.bdat.net/shell/node94.html
La orden nohup lanza un proceso y lo independiza del terminal que estamos usando. Los procesos se organizan de forma jerárquica, de forma que si abandonamos la shell que nos conectó al sistema (abandonamos la sesión de trabajo) automáticamente se matarán todos los procesos que dependan de ella. Pero en muchas ocasiones no puede interesar lanzar un proceso y dejarlo en ejecución aun cuando hayamos cerrado la sesión de trabajo. Para esto se usa la orden nohup. Esta orden se usa como:
- Código: Selecionar todos
nohup comando
Man:
http://es.tldp.org/Paginas-manual/man-p ... hup.1.html
nohup ejecuta el comando (command) dado ignorando los signals de hangup y con la prioridad de planificación incrementada en 5, de tal manera que el comando pueda continuar ejecutándose en background después de salir del sistema. Si la salida estándar es un tty, la salida y el error estándar son redireccionados de tal manera que apunten al fichero `nohup.out'; si no puede escribirse en dicho fichero, son apuntados al fichero `$HOME/nohup.out'. Si no puede escribirse en el, el comando no es ejecutado.
Si nohup debe crear el fichero `nohup.out' o `$HOME/nohup.out', se creará sin permisos de acceso para el grupo y otros. No cambiará los permisos de aquellos ficheros que ya existieran anteriormente.
nohup no pone en background directamente el comando que ejecuta; debe hacerse explícitamente, acabando la linea de comando con un `&'.
- Código: Selecionar todos
nohup comando &
Codigo fuente:
- Código: Selecionar todos
#if 0
#ifndef lint
static const char copyright[] =
"@(#) Copyright (c) 1989, 1993\n\
The Regents of the University of California. All rights reserved.\n";
#endif /* not lint */
#ifndef lint
static char sccsid[] = "@(#)nohup.c 8.1 (Berkeley) 6/6/93";
#endif /* not lint */
#endif
#include <sys/cdefs.h>
#include <sys/param.h>
#include <sys/stat.h>
#include <err.h>
#include <errno.h>
#include <fcntl.h>
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
static void dofile(void);
static void usage(void);
#define FILENAME "nohup.out"
/*
* POSIX mandates that we exit with:
* 126 - If the utility was found, but failed to execute.
* 127 - If any other error occurred.
*/
#define EXIT_NOEXEC 126
#define EXIT_NOTFOUND 127
#define EXIT_MISC 127
int
main(int argc, char *argv[])
{
int exit_status;
while (getopt(argc, argv, "") != -1)
usage();
argc -= optind;
argv += optind;
if (argc < 1)
usage();
if (isatty(STDOUT_FILENO))
dofile();
if (isatty(STDERR_FILENO) && dup2(STDOUT_FILENO, STDERR_FILENO) == -1)
/* may have just closed stderr */
err(EXIT_MISC, "%s", argv[0]);
(void)signal(SIGHUP, SIG_IGN);
execvp(*argv, argv);
exit_status = (errno == ENOENT) ? EXIT_NOTFOUND : EXIT_NOEXEC;
err(exit_status, "%s", argv[0]);
}
static void
dofile(void)
{
int fd;
char path[MAXPATHLEN];
const char *p;
/*
* POSIX mandates if the standard output is a terminal, the standard
* output is appended to nohup.out in the working directory. Failing
* that, it will be appended to nohup.out in the directory obtained
* from the HOME environment variable. If file creation is required,
* the mode_t is set to S_IRUSR | S_IWUSR.
*/
p = FILENAME;
fd = open(p, O_RDWR | O_CREAT | O_APPEND, S_IRUSR | S_IWUSR);
if (fd != -1)
goto dupit;
if ((p = getenv("HOME")) != NULL && *p != '\0' &&
(size_t)snprintf(path, sizeof(path), "%s/%s", p, FILENAME) <
sizeof(path)) {
fd = open(p = path, O_RDWR | O_CREAT | O_APPEND,
S_IRUSR | S_IWUSR);
if (fd != -1)
goto dupit;
}
errx(EXIT_MISC, "can't open a nohup.out file");
dupit:
if (dup2(fd, STDOUT_FILENO) == -1)
err(EXIT_MISC, NULL);
(void)fprintf(stderr, "appending output to %s\n", p);
}
static void
usage(void)
{
(void)fprintf(stderr, "usage: nohup [--] utility [arguments]\n");
exit(EXIT_MISC);
}
''---
les pido que lo prueben
como creo que no lo habian nombrado antes pondre como se usa un poco detallado
se conectan por ssh y buscan un comando que demore
en el ejemplo usare wget pero puede ser cualquier comando
lo ejecutan de esta manera por ejemplo
(la url es ficcticia)
- Código: Selecionar todos
nohup wget ftp://isobfw.iso &
rápidamente cierran la sesion (antes de que termine el comando)
y al rato vuelven a abrirla y revisan si se descargo la iso
y se debe haber creado un log que se llamara nohup.out
lo bueno es qe no tienen que esperar que se termine el comando para terminar la sesion ssh
o bien no pierden el trabajo en caso de que la sesion ssh se corte
pd
wget tiene una opción -b que es similar a usar wget + nohup pero no esta implementada en bfw