[Home]Signals

Last edit: Peter Favrholdt on July 2, 2006 18:10 (4157 days, 21 hours and 48 minutes ago) (diff)
Rtai.Dk | RecentChanges | Preferences | DIAPM RTAI

Date: Thu, 24 Jul 2003 14:29:16 -0400

I contacted Michael Kralka offline about LXRT & signals, and he was kind
enough to give me this primer on what he has learned:

Hi Michael,
I don't mind you contacting me directly, however I do suggest you post
this reply to the mailing list so others can learn from my response.

AFAICS, LXRT and Linux signals DO NOT play very well together. There
seems to be some hooks in LXRT to implement support for Linux signal
handling (see RT_SET_LINUX_SIGNAL_HANDLER in rtai_lxrt.h, tabnewlxrt.c,
and lxrt_table.c) but it is unimplemented.

Before delving into signals, make sure you are familiar with how signals
are processed (in particular with multiple threads - if your app is
multithreaded).

First and foremost, Sending SIGTERM or SIGKILL to a process kills it
ASAP, unless you have installed a signal handler (which you can't do for
SIGKILL). If a process is UNINTERRUPTABLE, the signal will be "pending"
until the task is no longer UNINTERRUPTABLE. When this happens, Linux
will handle the signal. HARD realtime LXRT processes and those that are
blocked on an RTAI object (such as a semaphore) are "owned" by RTAI and
_NOT_ Linux. This is done by putting the task into the UNINTERRUPTABLE
state.
    # man ps
    # ps aux
Should confirm this.

My suggestion
-------------
First, in rt_spread_timed, you don't have access to the semaphore that
your task blocks on, nor is there a way to unblock this task, without
hacking spdrv.

You might want to try the following:
- Add a signal handler to your LXRT app that captures the SIGTERM signal
(man signal or man sigaction). In this handler, do something that shuts
down your app (e.g. set some flag).
- Change the wait forever, with a timed way, say 10 seconds. If you read
no bytes, check if the app is being shutdown (e.g. the shutdown flag),
if so, cleanup, if not, continue with your loop.

Worst case, you app will shut down 10 seconds later. It that is too
long, shorten the time. This is how I handle the SIGTERM signal in my
app.

E.g.

void sighandler (int sig) {
        shutdown_flag=1;
}

while (!shutdown_flag) {
        num_read = rt_spread_timed (port, buf, cnt, ten_seconds) - cnt;
        if (num_read > 0) {
                /* Process num_read bytes in buf */
        }
}

BTW, your problem is COMPLETELY unrelated to mine :-). Mine deals with
signals generated internally (i.e. divide by zero, or segmentation
fault).

Regards,
Michael

Edit text of this page | View other revisions | Download Rtai.dk
Search: