Thread: problem with fork command after solaris to Linux porting

  1. #1
    Registered User
    Join Date
    Jul 2009
    Posts
    4

    problem with fork command after solaris to Linux porting

    Hi All,

    I am doing c++ application porting from Solaris/SPARK to Linux/x86. When i run my application on linux it crashes after a fork call.Actually parent process has exit call to make the child daemon process, but after fork call child gets SIGSEGV & terminates.

    Can anyone help me to find out the actual cause. Thanks in advance.



    following are the lines from strace output
    Code:
    clone(Process 23250 attached
    child_stack=0, flags=CLONE_CHILD_CLEARTID|CLONE_CHILD_SETTID|SIGCHLD, child_tidptr=0xb7f40928) = 23250
    [pid 23250] time([1247829456])          = 1247829456
    [pid 23250] open("/etc/localtime", O_RDONLY) = 3
    [pid 23250] fstat64(3, {st_mode=S_IFREG|0644, st_size=109, ...}) = 0
    [pid 23250] fstat64(3, {st_mode=S_IFREG|0644, st_size=109, ...}) = 0
    [pid 23250] mmap2(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0xb7f61000
    [pid 23250] read(3, "TZif\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\4\0\0\0\4\0"..., 4096) = 109
    [pid 23250] close(3)                    = 0
    [pid 23250] munmap(0xb7f61000, 4096)    = 0
    [pid 23250] --- SIGSEGV (Segmentation fault) @ 0 (0) ---
    Process 23250 detached
    - Amit

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    What makes you think your program was bug-free on the Solaris machine?

    The fact that it doesn't crash doesn't mean that your program is bug-free.

    These system calls are used by millions of people every day, so the chance that you can just arrive and instantly find a bug in them is remote to say the least.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,268
    What might help you out is ensuring that core files are enabled on the system. Run "ulimit -c unlimited", then run the program again so that it crashes. It should leave you with a core file that you can load with GDB. That can tell you some more information on what caused the crash.

    For this to be helpful, you will need to make sure the application is built with debugging symbols (The -g option passed to GCC).

  4. #4
    Registered User
    Join Date
    Jul 2009
    Posts
    4
    Thanks for your suggestions.Core file points to a different location for the failure.

    The application is crashing at insert() function of a map. The map variable is the static member variable of a class. But when i write the sample pgm with the same scenario it works fine.
    I use following flags while compiling application.
    CFLAGS_STATIC_LINKING = -Wall
    LD_FLAGS_STATIC_LINKING = -O3 -nostdlib

    Please give your suggestions.

    Code:
    File TMap.h
    ============================================
    #include<map>
    
    using namespace std;
    
     class TMap
     {
    public:
    typedef map<string, string> TestMap;
    static void func();
    private:
            static TestMap m_TestMap;
     };
    =============================================
    File TMap.cpp
    =============================================
    #include<iostream>
    #include"TMap.h"
    
    using namespace std;
    
    //typedef map<string, string> TestMap;
    TMap::TestMap TMap::m_TestMap;
    
    int main()
    {
            TMap::func();
            return 0;
    }
    
    void TMap::func()
    {
            cout << "Start ::" <<endl;
            m_TestMap.insert(TMap::TestMap::value_type("HI","Hello"));
            cout << "End :: %u" << &m_TestMap <<endl;
    }

  5. #5
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,981
    Why are you using "-nostdlib"? I believe that will prevent global object constructors from being called.

    gg

  6. #6
    Registered User
    Join Date
    Jul 2009
    Posts
    4
    I am porting a Solaris application to Linux, so makefile has the same syntax as of solaris.

    I got the solution.Thanks alot for your help guys...

  7. #7
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,981
    >> I got the solution.
    Which was....?

    gg

  8. #8
    Registered User
    Join Date
    Jul 2009
    Posts
    4
    removal of -nostdlib did the work

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. fork(), exit() - few questions!
    By s3t3c in forum C Programming
    Replies: 10
    Last Post: 11-30-2004, 06:58 AM
  2. Porting the NES emulator from DOS to Linux
    By billholm in forum Game Programming
    Replies: 14
    Last Post: 08-03-2002, 01:48 AM
  3. Problem w/ porting and static...
    By QuestionC in forum C++ Programming
    Replies: 4
    Last Post: 06-08-2002, 05:47 PM
  4. fork() problem
    By Unregistered in forum Linux Programming
    Replies: 3
    Last Post: 05-12-2002, 10:50 AM
  5. I need help with a linux problem
    By Korn1699 in forum A Brief History of Cprogramming.com
    Replies: 3
    Last Post: 12-07-2001, 04:45 PM