All of lore.kernel.org
 help / color / mirror / Atom feed
From: Gilles Chanteperdrix <gilles.chanteperdrix@xenomai.org>
To: Mehmet Alphan Ulusoy <alphan@domain.hid>
Cc: xenomai@xenomai.org
Subject: Re: [Xenomai-help] Zombie user tasks
Date: Thu, 27 Nov 2008 20:39:50 +0100	[thread overview]
Message-ID: <492EF786.4040303@domain.hid> (raw)
In-Reply-To: <20081127175234.163sujmgcgcgs4gk@domain.hid>

Mehmet Alphan Ulusoy wrote:
> void terminateGracefully(int sig)
> {
>      int err;
> 	    while (( err = rt_task_delete(&tid)) != 0)
> 	    {
> 	        printf("Error deleting task. Code %d.\n");
> 	    }
> 	    while (( err = rt_alarm_delete(&aid)) != 0)
> 	    {
> 	        printf("Error deleting alarm. Code %d.\n");
> 	    }
> 	    while (( err = rt_pipe_delete(&pidMon)) != 0)
> 	    {
> 	        printf("Error deleting pipe. Code %d.\n");
> 	    }
> 	    while (( err = close(sid)) != 0)
> 	    {
> 	        printf("Error deleting socket. Code %d.\n");
> 	    }
> 	}

This code is seriously broken. You risk an infinite loop which may brick
your box, if ever it happens over a thread with the SCHED_FIFO policy.
All these calls are not async signal safe, so should not be called in a
signal handler. Almost the only thing permitted in a signal handler is
to call sem_post, or to set a flag used by your application when a
syscall returns EINTR.

> - The child process which makes the system() call has a signal handler  
> installed for SIGCHILD signal and calls wait() to collect their exit  
> status.

The handler for SIGCHLD should be installed in the parent process, not
the children.

> 
> signal(SIGCHLD, waitChild);
> 
> void waitChild(int sig)
> {
> 
>      int status =0;
> 
>      wait(&status);
> 
> }

That is incorrect, you may receive SIGCHLD only once for several
children termination, so, you should call wait4 in non blocking mode
until it returns EWOULDBLOCK.

Or you should ignore explicitely SIGCHLD altogether, passing SIG_IGN to
signal or sigaction, Linux will then take care correctly of terminated
children.

> Is there a specific order to follow while deleting real-time entities?  
> Is the system() call or "pkill -SIGTERM" the problem?

why using system, why not using the kill service directly?

-- 
					    Gilles.


  parent reply	other threads:[~2008-11-27 19:39 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-11-27 15:52 [Xenomai-help] Zombie user tasks Mehmet Alphan Ulusoy
2008-11-27 15:55 ` Gilles Chanteperdrix
2008-11-27 19:39 ` Gilles Chanteperdrix [this message]
2008-11-28 16:19   ` Mehmet Alphan Ulusoy
2008-11-28 16:23     ` Gilles Chanteperdrix
2008-11-28 16:29       ` Mehmet Alphan Ulusoy
2008-11-28 16:40         ` Gilles Chanteperdrix
2008-11-28 17:11         ` Gilles Chanteperdrix
2008-11-28 20:53           ` Alphan Ulusoy
2008-12-21 19:28           ` Alphan Ulusoy
2008-12-21 20:05             ` Alphan Ulusoy
2008-12-21 21:40               ` Alphan Ulusoy
2008-12-22  9:48                 ` Gilles Chanteperdrix
2008-12-22 11:32                   ` Mehmet Alphan Ulusoy
2008-12-22 13:03                     ` Gilles Chanteperdrix
2008-12-23  5:46                       ` Alphan Ulusoy
2008-12-23 10:53                         ` Gilles Chanteperdrix
2008-12-23 11:46                           ` Alphan Ulusoy
2008-12-23 11:50                             ` Gilles Chanteperdrix
     [not found]                           ` <9EB4E9E6-B9D4-433C-ABC9-FBBEF29DB0A3@domain.hid>
     [not found]                             ` <4950DB54.3000804@domain.hid>
     [not found]                               ` <C59B6CFD-F977-4130-B8D9-DEB86F055160@domain.hid>
     [not found]                                 ` <4950DE5E.6040700@domain.hid>
2008-12-27 13:04                                   ` Alphan Ulusoy

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=492EF786.4040303@domain.hid \
    --to=gilles.chanteperdrix@xenomai.org \
    --cc=alphan@domain.hid \
    --cc=xenomai@xenomai.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.