1

I am trying to check for a running server process in a Boost UTF global fixture. I am doing this with a call to system in my fixture constructor like this...

class MyTestFixture
{
public: 
    MyTestFixture(); 
    ~MyTestFixture() ;

};


MyTestFixture::MyTestFixture()
{

    int rc = system("pidof myserver > /dev/null");
    if ( rc != 0 )
    {
        cout << "myserver not running so cannot continue" << endl;
        fflush (stdout) ;
        sleep(10);
        exit(4) ;
    }

    cout << "fixture setup ok!" << endl ;
}

BOOST_GLOBAL_FIXTURE( MyTestFixture );


BOOST_AUTO_TEST_CASE( pgmiia_main_test1 )
{
// some test code...
}

When "myserver" is running ok everything is fine, but when it isnt I get a crash. and it doesnt go into the if section and exit. Strangely if I run it in gdb with myserver not running, it does go into my exit branch as I expect.

I'm a bit new to Boost UTF. I am doing this with a dynamic link. Any ideas?

Jon

CharlesB
  • 86,532
  • 28
  • 194
  • 218
Jon Tilson
  • 11
  • 1

1 Answers1

1

As far as I remember, pidof -s 'proc_name' returns 0 if the proc_name is not running and PID otherwise. Since system should return the retval of the called process, you are actually testing if the process is running: rc != 0, whereas rc == 0 tests if the process is not running. Not sure if the issue somehow relates to the Boost specifics.

Oleg
  • 126
  • 2
  • sorry there is a typo in my code...I meant to say rc == 0. As you can imagine Ive tried a variety of things already to detect a running prcoess and "pidof" and "pgrep" seem much the same, both supposedly returning zero if no matching process is found. It works fine from a logically identical shall script, but that's another thing. – Jon Tilson Jul 05 '12 at 15:12
  • hm. then I think it is somehow related to the Boost global fixture. It's a global initialization routine. If the program get crashed with Boost and only when you enter _if_ block... try to comment out _exit(4)_ that is try to set up a fixture w/o teardown routine. – Oleg Jul 05 '12 at 17:31