Sponsored Content
Full Discussion: nohup and & versus functions
Special Forums UNIX and Linux Applications nohup and & versus functions Post 302514393 by Corona688 on Friday 15th of April 2011 02:52:56 PM
Old 04-15-2011
Shell functions don't work anywhere except inside the shell. nohup is not part of the shell, so you can't feed it a function.

from man nohup you can tell that nohup does the following things:
  1. Ignore the HUP signal
  2. Redirect stdout into a file
  3. Redirect stderr into /dev/null
  4. Redirect stdin from /dev/null

All of that can be done in the shell with no help from nohup.

Code:
trap "true" HUP # Do nothing but run "true" on SIGHUP
# runs a shell function in the background, with its files redirected
# the same way nohup does.  & puts it in the background.
# 'disown' tells the shell not to wait for it on exit.
# disown isn't available in some shells, but if the shell
# doesn't have it, it also doesn't need it.
function > logfile 2> /dev/null < /dev/null & disown

 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Alias's & Functions - simple question

Having a memory lapse: If I redefine a command using an alias or a function - How do I access the "real" command without specifying an absoulte path: i.e. function man { /usr/bin/man |more } alias ls='/usr/bin/ls -l' How do I specify the ls or man command above without the... (6 Replies)
Discussion started by: kornshellmaven
6 Replies

2. UNIX for Advanced & Expert Users

vi search & replace functions

I'm trying to do a global search and replace in vi. I am trying to replace a string, call it "BOB" with a carriage return and can't seem to find a reference to it. Command syntax s%/BOB/???/g What would I substitute the "???" with? (7 Replies)
Discussion started by: barnettdk
7 Replies

3. Solaris

encryption & decryption functions in sun solaries

hi, is there any library functions available in sun solaries for encryption and decryption functions. regards suresh (1 Reply)
Discussion started by: suresh_rtp
1 Replies

4. Shell Programming and Scripting

Execute Script using nohup and &

Hi all, I have one script test.sh for which I pass two arguments. In the same script I need to submit this script in background using nohup. My script like this and it is working in HP-UX os but not Solaris. #! /bin/sh if then MTR_PID=$$ export MTR_PID echo "test.sh $1 $2... (3 Replies)
Discussion started by: sridhar_423
3 Replies

5. Homework & Coursework Questions

C++ struct pointers & functions

Hi All, My latest assignment (practice not coursework!) is to write prototype interactive exam/test console application. I've used structs to store the question information (not sure if this was the best way to do it?) and I have the following code that outputs each question and it's possible... (0 Replies)
Discussion started by: pondlife
0 Replies

6. UNIX for Dummies Questions & Answers

nohup & mpiexec problems

Hi everyone - I'm trying to start a run of LAMMPS (which takes an input file) with mpiexec on multiple processors. I want to combine this with nohup so that I can log off the node. I've used the syntax below successfully on one cluster, but it doesn't work on the new one I'm using. Any... (0 Replies)
Discussion started by: erin85
0 Replies

7. Programming

Background (nohup * &) SSH command block possible?

Hello, I am trying to find a way to send several sequential commands via SSH to a remote box in a single command. Thoughts so far: 1) Can I put them into a function and call the function within the ssh command? e.g. ssh <targetserver> $(functionx) No - then it calls the function in... (4 Replies)
Discussion started by: doonan_79
4 Replies

8. UNIX for Dummies Questions & Answers

How to get a timestamp when running nohup & from a shell?

Hi, I am running nohup cp & in a shell script. How do I get a timestamp so I can get a timing of how long the copy took? Roughly, the script does something like below: date nohup cp -rp /files/source /files/target & date I am mainly wanting to know how long it took for the... (9 Replies)
Discussion started by: newbie_01
9 Replies

9. UNIX for Dummies Questions & Answers

Difference between & and nohup &

Hi All, Can anyone please help me understanding what the difference between the below two? 1. script.sh & 2. nohup script.sh & (2 Replies)
Discussion started by: Anupam_Halder
2 Replies

10. Red Hat

Nohup with ampersand & process gets disconnected

For years I have spawned shell scripts with nohup and ampersand and they run whether or not I stay logged in. Recently a client told us that we had to set a keep alive timeout on all of our Redhat 7.6 Linux servers. Our sysadmin set the following parameters in the sshd_config file on all of our... (10 Replies)
Discussion started by: gandolf989
10 Replies
NOHUP(1)						    BSD General Commands Manual 						  NOHUP(1)

NAME
nohup -- invoke a utility immune to hangups SYNOPSIS
nohup [--] utility [arguments] DESCRIPTION
The nohup utility invokes utility with its arguments and at this time sets the signal SIGHUP to be ignored. If the standard output is a ter- minal, the standard output is appended to the file nohup.out in the current directory. If standard error is a terminal, it is directed to the same place as the standard output. Some shells may provide a builtin nohup command which is similar or identical to this utility. Consult the builtin(1) manual page. ENVIRONMENT
The following variables are utilized by nohup: HOME If the output file nohup.out cannot be created in the current directory, the nohup utility uses the directory named by HOME to create the file. PATH Used to locate the requested utility if the name contains no '/' characters. EXIT STATUS
The nohup utility exits with one of the following values: 126 The utility was found, but could not be invoked. 127 The utility could not be found or an error occurred in nohup. Otherwise, the exit status of nohup will be that of utility. SEE ALSO
builtin(1), csh(1), signal(3) STANDARDS
The nohup utility is expected to be IEEE Std 1003.2 (``POSIX.2'') compatible. BUGS
Two or more instances of nohup can append to the same file, which makes for a confusing output. BSD
July 19, 2001 BSD
All times are GMT -4. The time now is 12:11 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy