Find the answer to your Linux question:
Page 1 of 2 1 2 LastLast
Results 1 to 10 of 14
Hi I have a program that runs ok when executed from the bash but ends up with a core dump when running from the crontab. The program is constructed in ...
  1. #1
    Just Joined!
    Join Date
    Oct 2009
    Posts
    7

    Unhappy Core dump when running from crontab

    Hi

    I have a program that runs ok when executed from the bash but ends up with a core dump when running from the crontab.
    The program is constructed in C/C++ and the linux platform is RedHat for Itanium 2.

    The program is executed by a script, the same in both situations, with the env set to be exactly equal (I checked this by printing env in each execution).

    What else changes when executing the same script from bash and crontab??

    The block of core that generates the core dump is apparently well constructed, it is a shared library used is many of my applications, none of which breaks.
    My only clue is that somehow the process addressing space is different when running from bash and crontab. Does it make any sense?

  2. #2
    Linux Newbie
    Join Date
    Mar 2009
    Posts
    228
    When something is run in crontab the user's profile isn't first executed as it is when you log in. So I suspect there's something else in your login profile that's missing thus causing the core dump. Maybe add to the script to source your login profile?

  3. #3
    Linux Guru Rubberman's Avatar
    Join Date
    Apr 2009
    Location
    I can be found either 40 miles west of Chicago, or in a galaxy far, far away.
    Posts
    8,974
    Have you run a post-mortem in the debugger? If necessary, build your executable with the -g option and don't strip the binaries so you can look at the call stack and variables.
    Sometimes, real fast is almost as good as real time.
    Just remember, Semper Gumbi - always be flexible!

  4. #4
    Just Joined!
    Join Date
    Oct 2009
    Posts
    7
    Hi!

    Quote Originally Posted by lomcevak View Post
    When something is run in crontab the user's profile isn't first executed as it is when you log in. So I suspect there's something else in your login profile that's missing thus causing the core dump. Maybe add to the script to source your login profile?
    In the script, executed both by crontab and manually on bash, I load the profile:
    . $HOMEPATH/.bashrc

    Everything in the env is equal!
    Is there anything else that differs crontab from bash?



    Quote Originally Posted by Rubberman View Post
    Have you run a post-mortem in the debugger? If necessary, build your executable with the -g option and don't strip the binaries so you can look at the call stack and variables.
    The code dump is complicated to explain, but I have the stack trace and the exact line where it crashes.
    The C++ binary loads JRockit JVM, therefore the exception in C++ code is caught by the JVM.
    Moreover the instruction is a simple initiation of a pointer to NULL, the same instruction that runs several times before.

    Can a process when runned from cron have a different address space? Or something like that? Which in the end give me an illegal memory access.



    Thanks!

  5. #5
    Linux Guru Rubberman's Avatar
    Join Date
    Apr 2009
    Location
    I can be found either 40 miles west of Chicago, or in a galaxy far, far away.
    Posts
    8,974
    Ok. So you are running Java code in the C++ program. My guess is that the PATH and/or other environment variables required for Java are not set right. Most specialized environment variables are set with ~/.bash_profile, not ~/.bashrc so you might want to make sure that you source that before ~/.bashrc.
    Sometimes, real fast is almost as good as real time.
    Just remember, Semper Gumbi - always be flexible!

  6. #6
    Just Joined!
    Join Date
    Oct 2009
    Posts
    7
    Quote Originally Posted by Rubberman View Post
    Ok. So you are running Java code in the C++ program. My guess is that the PATH and/or other environment variables required for Java are not set right. Most specialized environment variables are set with ~/.bash_profile, not ~/.bashrc so you might want to make sure that you source that before ~/.bashrc.
    I'll check those scripts, however if env has the same values the environment can be different?

    I tried to use strace to capture more information, and until now it made the error stop occurring.
    I used the command:
    strace -o /fullpath/strace.txt CMD

    Any clue why apparently the error stopped?

  7. #7
    Linux Guru Rubberman's Avatar
    Join Date
    Apr 2009
    Location
    I can be found either 40 miles west of Chicago, or in a galaxy far, far away.
    Posts
    8,974
    Another thought, and something that has bitten me on the rear a few times in the past with this problem, is the fact that cron is "headless" in that there is no terminal (tty) for input/output. There are some system calls that will cause an application to core dump if there is no valid stdin/stdout/stderr. That's why I suggested running a debuggable version of the application and they looking at the core file in the debugger to get a better idea where/why it was crashing. I suspect that strace is going to provide the command with some file descriptor for stdin/stdout/stderr so it can intercept error messages.
    Sometimes, real fast is almost as good as real time.
    Just remember, Semper Gumbi - always be flexible!

  8. #8
    Just Joined!
    Join Date
    Oct 2009
    Posts
    7
    Quote Originally Posted by Rubberman View Post
    Another thought, and something that has bitten me on the rear a few times in the past with this problem, is the fact that cron is "headless" in that there is no terminal (tty) for input/output. There are some system calls that will cause an application to core dump if there is no valid stdin/stdout/stderr. That's why I suggested running a debuggable version of the application and they looking at the core file in the debugger to get a better idea where/why it was crashing. I suspect that strace is going to provide the command with some file descriptor for stdin/stdout/stderr so it can intercept error messages.
    Do you mean that strace overcomes the limitation of having no stdin/stdout/stderr?

    In cron, I have register the command like this:

    /fullpath/script.sh >> /fullpath/file.log 2>&1

    I think that with this, the stderr is redirected to stdout, and both are redirected to file.log. Thus I should have no error related with the missing stdin/stdout/stderr, should I?

  9. #9
    Linux Guru Rubberman's Avatar
    Join Date
    Apr 2009
    Location
    I can be found either 40 miles west of Chicago, or in a galaxy far, far away.
    Posts
    8,974
    Quote Originally Posted by ph_trooper View Post
    Do you mean that strace overcomes the limitation of having no stdin/stdout/stderr?

    In cron, I have register the command like this:

    /fullpath/script.sh >> /fullpath/file.log 2>&1

    I think that with this, the stderr is redirected to stdout, and both are redirected to file.log. Thus I should have no error related with the missing stdin/stdout/stderr, should I?
    Well, you can try it. That should work I would think, but remember that I am only surmising that the I/O issue is your root cause. Without verification, which this should do, at least for stdout/stderr, we still cannot be sure.
    Sometimes, real fast is almost as good as real time.
    Just remember, Semper Gumbi - always be flexible!

  10. #10
    Just Joined!
    Join Date
    Oct 2009
    Posts
    7
    Quote Originally Posted by Rubberman View Post
    Well, you can try it. That should work I would think, but remember that I am only surmising that the I/O issue is your root cause. Without verification, which this should do, at least for stdout/stderr, we still cannot be sure.
    The redirection of the stdout and stderr are like that from the beginning, they did not solved the problem.
    I am stunned with the strace command 'solving' the issue!!

    Does the strace command alter the environment or anything that might change the outcome of the app execution?! Well, in fact it alters, but do you have any idea of what it might be?

Page 1 of 2 1 2 LastLast

Posting Permissions

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