How do I nohup a subprocess spawned from a commandline?
I have a bit complex to explain issue t开发者_StackOverflow社区hat I have ran into:
- I have a long running nohupped process that redirects its stderr into a file.
- However, I use a subprocess to stamp the stderr with a timestamp.
- The above mentioned subprocess unfortunately is not nohupped (my bad)!
- Now, How do I get this subprocess somehow nohupped and get the stderr preserved and keep coming to the file even after I log out. I have to logout of the server.
The commandline in question looks something like this:
$ nohup myscript.sh -op1 val1 -op2 val2 -op3 val3 >mystderr.txt 2> >(while read line; do echo "$(date): ${line}"; done > n100l1800g0.5.err ) < /dev/null &
The above technique of stamping stderr is learned recently right here at stackoverflow.
Thanks in advance for any clue.
The man page for the nohup
I have says nohup [ options ] command [arg ...]
.
I remember reading someplace that nohup
does not process pipelines, which I think is what you have.
Try remaking your pipeline processes as a script that accept the arguments and it should work.
I hope this helps.
Put your commands into a shell script and nohup the script.
so if yourscript contains :
#!/bin/bash
myscript.sh -op1 val1 -op2 val2 -op3 val3 >mystderr.txt 2> >(while read line; do echo "$(date): ${line}"; done > n100l1800g0.5.err ) < /dev/null
then from the command line
$ nohup yourscript &
精彩评论