nohup and & versus functions

Thread Tools Search this Thread
Special Forums UNIX and Linux Applications nohup and & versus functions
# 1  
Old 04-10-2011
Network nohup and & versus functions

when i have a function definition and function call in my script , i am unable to run my script in background with nohup..
Help me out please.....
# 2  
Old 04-11-2011
nohup can't run functions, period. nohup is not a shell builtin, so only runs executable files.

& should work, though. You can do nohup's signal-trapping + redirection in the shell itself too.

( trap "true" HUP ; myfunction ) > nohup.out 2>/dev/null </dev/null & disown

disown may not be needed on all shells.

If it doesn't work you'll need to post your complete code, plus what your system and shell is, to figure out what's going wrong.
This User Gave Thanks to Corona688 For This Post:
# 3  
Old 04-14-2011
would you please explain me a little more about what you said...Smilie
# 4  
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.

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

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. 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

2. 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. & 2. nohup & (2 Replies)
Discussion started by: Anupam_Halder
2 Replies

3. 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

4. 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

5. 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

6. 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

7. Shell Programming and Scripting

Execute Script using nohup and &

Hi all, I have one script 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 " $1 $2... (3 Replies)
Discussion started by: sridhar_423
3 Replies

8. 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

9. 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

10. 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
Login or Register to Ask a Question

Featured Tech Videos