LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices



Reply
 
Search this Thread
Old 10-13-2010, 03:18 AM   #1
smc2
LQ Newbie
 
Registered: Apr 2010
Posts: 29

Rep: Reputation: 0
Question nohup process does not get killed !!


hi ...
I call nohup in a script like follow but when I quite with ^c the stail program stil is in memory. as u can see I call a perl script within a shell script.

Code:
#!/bin/bash
if [ -z $1 ]; then
echo -e '\33[31m You Must enter a period time \33[0m'
exit 1
fi

nohup  ./stail1.1.pl sa 0 1 >/dev/null 2>&1 &
while [ true ]
do
 ...infinite loop...
 ....this loop just stop if user press ^c and stop the script----
done

Thanks in Advance..
 
Old 10-13-2010, 03:51 AM   #2
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374
Hi,

When you use nohup the program started (stail1.1.pl in this case) is detached from the terminal/shell and it will not react to any key combo's used in the original shell. Works as designed.

Without knowing what it is you are trying to do and if the stail1.1.pl program actually does need a nohup (and be put to the back ground) I can't give you a solution.

If stail1.1.pl finishes by itself you can probably remove the nohup (you might want to keep the &, depends....).
If stail1.1.pl is an endless loop that must be stopped by the user you need some other solution, which depends on what the main script and the perl script do/must do.

Hope this helps.
 
1 members found this post helpful.
Old 10-13-2010, 04:33 AM   #3
smc2
LQ Newbie
 
Registered: Apr 2010
Posts: 29

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by druuna View Post
Hi,

When you use nohup the program started (stail1.1.pl in this case) is detached from the terminal/shell and it will not react to any key combo's used in the original shell. Works as designed.

Without knowing what it is you are trying to do and if the stail1.1.pl program actually does need a nohup (and be put to the back ground) I can't give you a solution.

If stail1.1.pl finishes by itself you can probably remove the nohup (you might want to keep the &, depends....).
If stail1.1.pl is an endless loop that must be stopped by the user you need some other solution, which depends on what the main script and the perl script do/must do.

Hope this helps.
Dear druuna, thanks. Actualy stail is an script that act like tail. it tail a growing log-file and and withdraw some useful values from pile of data and wite them in a file. stail has lots of output and it distract user ==> I use nohup .
stail should be run while the main script is running. it produeces values that I need in main script (I actually sum these values with some other values and show them to the user).
if stail not closed when the main script is closed, then it remain in memory and
update the log file. so it case miscalculation when the main script run again. becuase now there two process (the old stail and new stail) are updateing a log file.

I hope these details make the problem more clear.
I realty appropriate your help.
 
Old 10-13-2010, 04:47 AM   #4
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374
Hi,

The script you posted in post #1 only starts stail1.1.pl. Nothing is done with the output (all output is discarded due to the 1>/dev/null and 2>&1). Starting stail1.1.pl with nohup and putting it in the background (&) is probably not needed in your case.

You probably need something like this:
Code:
#!/bin/bash

./stail1.1.pl sa 0 1 | while read LINE
do
  ... do something with or check $LINE ....
done
Depending on what you need to check you might want to include 2>/dev/null (./stail1.1.pl sa 2>/dev/null) to get rid of the errors generated or add 1>/dev/null if you are only interested in the errors.

Hope this helps.
 
Old 10-13-2010, 05:25 AM   #5
smc2
LQ Newbie
 
Registered: Apr 2010
Posts: 29

Original Poster
Rep: Reputation: 0
Sorry if I couldn't clarify completely.
stail is like tail and has some built in functions that deal with output theselfs. the importatn thing is that it should be ran as
the main script is running and close when the main is closed.
the main script uses the an output file that stail will create as it is working
 
Old 10-13-2010, 09:38 AM   #6
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374
Hi,

The example I gave does what you ask for.

When you start the script (the example given in post #4), stail1.1.pl is started and the output is given, a line at the time, to the while read loop. Inside the while read loop you can do what you want/need with the individual lines.

If you stop the example script (ctrl-c) the stail1.1.pl is also killed.

Here's an example where stail1.1.pl is replaced by a tail -f on a log file. It looks for the word completed and prints the date/time and the process:
Code:
#!/bin/bash

tail -f /var/log/allmessages | \
while read LINE
do
#  echo $LINE
  awk '/completed/ { print $1, $2, $3, $5 }'
done
Example run:
Code:
first is example output generated by the tail -f process
$ tail -f /var/log/allmessages
Oct 13 15:20:00 exile fcron[21639]: Job /usr/lib/sa/sa1 & started for user admin (pid 21640)
Oct 13 15:20:02 exile fcron[21639]: Job /usr/lib/sa/sa1 & completed
Oct 13 15:25:00 exile fcron[21706]: Job /usr/lib/sa/sa1 & started for user admin (pid 21707)
Oct 13 15:25:02 exile fcron[21706]: Job /usr/lib/sa/sa1 & completed
Oct 13 15:30:00 exile fcron[21820]: Job /usr/lib/sa/sa1 & started for user admin (pid 21821)
Oct 13 15:30:02 exile fcron[21820]: Job /usr/lib/sa/sa1 & completed
Oct 13 15:35:00 exile fcron[21903]: Job /usr/lib/sa/sa1 & started for user admin (pid 21904)
Oct 13 15:35:02 exile fcron[21903]: Job /usr/lib/sa/sa1 & completed

running the script
$ ./tester.sh
Oct 13 15:20:02 fcron[21639]:
Oct 13 15:25:02 fcron[21706]:
Oct 13 15:30:02 fcron[21818]:
Oct 13 15:30:02 fcron[21820]:
Oct 13 15:35:02 fcron[21903]:
Hope this clears things up a bit.
 
1 members found this post helpful.
  


Reply

Tags
kill, nohup, shell scripting


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
find history of a job killed by "kernel: Out of Memory: Killed process" poulacou Linux - Server 3 09-20-2007 05:24 PM
nohup command used but process is still killed helptonewbie Linux - Newbie 4 02-13-2007 05:44 PM
problem with nohup command and nohup file size vbseeker Linux - General 1 09-17-2006 12:36 PM
nohup process dosen't complete JeffCrew Linux - Newbie 1 10-13-2005 11:38 PM
nohup not preventing jobs from getting killed TrulyTessa Linux - Newbie 4 12-24-2004 12:39 PM


All times are GMT -5. The time now is 03:59 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration