LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Desktop
User Name
Password
Linux - Desktop This forum is for the discussion of all Linux Software used in a desktop context.

Notices



Reply
 
Search this Thread
Old 01-24-2007, 10:41 AM   #1
C. Alan
LQ Newbie
 
Registered: Jan 2007
Location: Tehachapi, CA
Distribution: Fedora 6
Posts: 3

Rep: Reputation: 0
Dealing with a Memory Leak


I have a piece of software I run on Gnome that is giving me problems. It is a weather station logger, meaning it communicates with with my Com port to get data from my home weather station. The issue is the fact that the Com port library the author used in the software has a pretty serious memory leak when run with Fedora 6. It will run for about 16 hours before it fills up my system memory, and Linux kills the process.

The author of the software is a ware of the problem, and he is trying his best to fix it. In the mean time, I have to stop the software, and restart it every 12 hours.

I am looking for a way to automate the shutdown, and restarting of the software. The program runs in Gnome, and has to be started from a terminal window, and then has a Xwindows interface.

I am still a relitive linux newbie, and I am sure what I need to do can be done with a shell script and cron, but I just don't know how to put the pieces together.

Idealy, the shells script would identify the terminal the program is running in, kill the program process, wait 1 minute, and then run the script that restarts the program in the same terminal window.

Can anyone help me with this?
Thanks,
C. Alan
 
Old 01-24-2007, 11:47 AM   #2
unSpawn
Moderator
 
Registered: May 2001
Posts: 27,814
Blog Entries: 54

Rep: Reputation: 2990Reputation: 2990Reputation: 2990Reputation: 2990Reputation: 2990Reputation: 2990Reputation: 2990Reputation: 2990Reputation: 2990Reputation: 2990Reputation: 2990
Suppose the application is "/usr/local/bin/applicationname", make a script and save it as "/usr/local/bin/restart_applicationname.sh":
Code:
#!/bin/sh
# set -x
[ -z $DISPLAY ] && export DISPLAY=":0.0"
_app="/usr/local/bin/applicationname"
_kill() { /usr/bin/pkill -KILL -f "$_app*" || _kill; }
kill && sleep 1m && exec $_app
exit 0
Make the script executable, then run it. If the application disappears then reappears it works. If the script doesn't work please uncomment the "set -x" line, run again and post the output. On to making the crontab entry. As user run "crontab -e". Add a line:
Code:
00 */12 * * * /usr/local/bin/restart_applicationname.sh
save, close, done.


*Only thing this doesn't do is start it from a terminal window, maybe explain why it should be?
 
Old 01-24-2007, 12:15 PM   #3
C. Alan
LQ Newbie
 
Registered: Jan 2007
Location: Tehachapi, CA
Distribution: Fedora 6
Posts: 3

Original Poster
Rep: Reputation: 0
Thanks for your help. I will put the script together and try it tonight when I get home.

I was conserned about it running in the same terminal window because The interface is in Gnome, and I was conserned that if cron started the job, I would not be able to see the program interface on the desktop (maybe I am thinking about this too much ). I thought that if I linked the scripted to a particular terminal session (or xwindows session), the program interface would alway appear on the desktop for the current user.

I suppose I could just kill the job again and restart it from a terminal window when I need to get to the interface. The program logs weather observations every 5 minutes, and then feeds them to www.wunderground.com. If I miss an update, it is not the end of the world. I just don't want it down for 3 days when I am out of town, and the system runs out of memory.

Last edited by C. Alan; 01-24-2007 at 12:16 PM.
 
Old 01-25-2007, 12:00 AM   #4
C. Alan
LQ Newbie
 
Registered: Jan 2007
Location: Tehachapi, CA
Distribution: Fedora 6
Posts: 3

Original Poster
Rep: Reputation: 0
Well, I had to tweak it a little to make it work, but it does appear to work now. Here is the Final code I ended up using:

Code:
#!/bin/sh
# set -x
[ -z $DISPLAY ] && export DISPLAY=":0.0"
_app="<path to App>"
pkill -KILL App
sleep 15
export LD_LIBRARY_PATH=<library path for app>
exec $_app
exit 0
It kept choking on the pkill part until I simplified it to just the name of the applciation. The application has a starup script that loads a library prior to executing, so I just used the same export command that was in the startup script for the application.

I ran it through cron with a 2 minute delay, and it works just as I hoped. So I then bumped my delay up to 4 hours (00 */4 * * *) and I will see tomorrow if it has worked.

Thanks for your help!
--C. Alan
 
  


Reply


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
Memory leak?! nyk Programming 10 01-24-2005 08:08 PM
memory leak mdk Mandriva 1 09-17-2004 11:54 AM
possible memory leak?? matt80 Linux - General 2 07-02-2004 12:07 AM
Memory Leak when using memory debugging C program on SuSE SLES8 babalina Linux - Distributions 0 10-06-2003 10:39 AM
Memory Leak FredrikN Linux - General 4 09-17-2002 04:16 PM


All times are GMT -5. The time now is 12:30 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