discuss-gnuradio
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Discuss-gnuradio] Daemonizing a flowgraph


From: devin kelly
Subject: [Discuss-gnuradio] Daemonizing a flowgraph
Date: Tue, 11 Jul 2017 16:39:55 -0400

Hello,

I have a flowgraph that I made with  GRC and modified.  All I want to do with the flowgraph is make it run as a daemon.  I understand that if there are overflows or underflows I'll miss them, that's OK.

I added some basic python code to daemonize my flowgraph:


        # Fork once
        try:
            pid = os.fork()
        except OSError:
            print 'error forking'

        if pid > 0:  # if parent, return
            return

        os.umask(0)

        # Reset the session ID
        try:
            os.setsid()
        except OSError:
            sys.exit(1)

        # Fork twice, giving up ownership of first parent's SID
        try:
            pid = os.fork()
        except OSError:
            print 'error forking'

        if pid != 0:  # if parent, return
            sys.exit(0)

        # Change PWD
        try:
            os.chdir('/')
        except OSError:
            return

        # Close open files
        sys.stdin.close()
        sys.stdout.close()
        sys.stderr.close()

        with open('/dev/null', 'r+') as devnull:
            sys.stdin = devnull
            sys.stdout = devnull
            sys.stderr = devnull

    tb = top_block_cls(options)
    tb.start()
    time.sleep(60.0)
    tb.stop()
    tb.wait()

When I run this, it works at first (I get my prompt back, you can see me trying to open the file).  But then the UHD hijacks my stdout/stderr and resumes as if nothing happened.

$ ./flowgraph.py -t 30                                                                                             
linux; GNU C++ version 4.8.4; Boost_105500; UHD_003.009.005-0-g32951af2

$ vim flowgraph.py -- X300 initialization sequence...                                                              
-- Determining maximum frame size... 1472 bytes.
-- Setup basic communication...
-- Loading values from EEPROM...
-- Setup RF frontend clocking...
-- Radio 1x clock:200
-- Initialize Radio0 control...
-- Performing register loopback test... pass
-- Initialize Radio1 control...
-- Performing register loopback test... pass

How do I stop the UHD from doing this?

Thanks for any help,
Devin

reply via email to

[Prev in Thread] Current Thread [Next in Thread]