Find the answer to your Linux question:
Results 1 to 6 of 6
OS: SuSE 10.2 NOTE: I am a Linux newcomer so please try to explain your responses in detail. I have a C/C++ app that I trigger from a daemon (so ...
  1. #1
    Just Joined! mitchpotter's Avatar
    Join Date
    Jan 2008
    Location
    Orlando
    Posts
    19

    Question App stops running after a couple of hours

    OS: SuSE 10.2

    NOTE: I am a Linux newcomer so please try to explain your responses in detail.

    I have a C/C++ app that I trigger from a daemon (so it keeps running when I close the shell) when booting to 3 or 5. The app runs great for the first hour or two then just stops. I'm not sure if the app actually closes or if the system is forcing it to go idle because it is sitting in a loop.

    The app looks for new files in a specified directory then processes them based on their contents. As long as there is a steady stream of files to process the app will run forever, but of course there are times when no new files arive for a long time. If the app doesn't process anything for a while (between 1 and 3 hours per my tests) it seems to stop.

    Additional info:
    The app is completely automated, no user input.

    What I would like to know:
    Is there any way to check to see if the process is still running?
    Can I make the daemon that triggers the app restart it if it stops?
    If it is still running what might be causing it to hang?
    Does the OS have any settings that would stop the app because it is just looping?
    Would the OS power settings restrict or stop the app if the computer initiates an idle or powersave state?
    Is there a better way to trigger an app that should always be running?

    Thanks in advance.

  2. #2
    Linux Guru coopstah13's Avatar
    Join Date
    Nov 2007
    Location
    NH, USA
    Posts
    3,149
    Code:
    ps -A
    prints out all running processes, you can pipe to grep and filter out based on the process name if you like.

    I would highly suggest changing the way your application works. It shouldn't constantly scan the directory, you should have it only scan once in a while otherwise its just going to eat up your resources, consider using a thread and have it check the directory and keep the contents in memory, and then sleep say 30 seconds or 60 seconds and check again and compare to what you had previously

  3. #3
    Just Joined! mitchpotter's Avatar
    Join Date
    Jan 2008
    Location
    Orlando
    Posts
    19

    Question

    Quote Originally Posted by coopstah13 View Post
    Code:
    ps -A
    prints out all running processes, you can pipe to grep and filter out based on the process name if you like.

    I would highly suggest changing the way your application works. It shouldn't constantly scan the directory, you should have it only scan once in a while otherwise its just going to eat up your resources, consider using a thread and have it check the directory and keep the contents in memory, and then sleep say 30 seconds or 60 seconds and check again and compare to what you had previously
    First, Thanks for the reply. I used ps -A and it does show the process. In fact, it shows it three times. It looks like it shows most processes multiple times in the list so I'm guessing that normal. And even though the app is listed in the process list, it is no longer performing the scan loop. At least it looks like it isn't because there are files sitting in the scan directory and not being processed.

    Second, a little more info on my app might be helpful. It does sleep for a while between scans.
    Code:
    usleep( 10000000 );
    I know that's only 10 seconds but this app is the computer's main function. The computer is part of a test farm and this app is the controller for the processes it performs. So this is not my desktop computer; it's just hanging out in my server closet with a bunch of other computers.

    Previously the app worked only the first few minutes after it started. Then I had a friend suggest I print something (printf()) every time I went through the scan loop. This increased the length of time the app would function but did not completely solve the problem. I need the app to run for long periods of time.

    Is there another way to automatically trigger the app when the computer starts without using a daemon and without attaching to a remote shell when I start it from my PC?

  4. #4
    Linux Guru gogalthorp's Avatar
    Join Date
    Oct 2006
    Location
    West (by God) Virginia
    Posts
    3,105
    It is not normal for ps to show multiple instances. So it looks like for some reason you have started multiple instances. Each instance will have a unique process ID (PID) the first column.

    In your code look for integer counters that might be overflowing or other conditions that could lead to infinite loops. The problem is most likely in the App.

  5. #5
    Just Joined! mitchpotter's Avatar
    Join Date
    Jan 2008
    Location
    Orlando
    Posts
    19
    This is how I fixed it.

    The code was the problem. I was using opendir() and readdir() to check for new files. The problem was I wasn't using closedir() at the end of the function so it was leaking memory and eventually no longer identifying files in the directory. I switched to scandir() which handles all that open and close stuff on it's own and returns a nice array of file names which is easy enough to parse.

    Thanks for the help all.

  6. #6
    Linux Guru gogalthorp's Avatar
    Join Date
    Oct 2006
    Location
    West (by God) Virginia
    Posts
    3,105
    That would do it.

    You did not follow Mom's rule of programming.

    Put things back the way you found them!!!!

    I bet you did not know your mom was a programmer

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...