mirror of
https://github.com/apache/nuttx.git
synced 2026-06-06 00:14:22 +08:00
Add logic to retain child task exit status if so configured
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@5553 42af7a65-404d-4744-a932-0658087f49c3
This commit is contained in:
+69
-2
@@ -334,12 +334,79 @@ defconfig -- This is a configuration file similar to the Linux
|
|||||||
CONFIG_TASK_NAME_SIZE - Specifies that maximum size of a
|
CONFIG_TASK_NAME_SIZE - Specifies that maximum size of a
|
||||||
task name to save in the TCB. Useful if scheduler
|
task name to save in the TCB. Useful if scheduler
|
||||||
instrumentation is selected. Set to zero to disable.
|
instrumentation is selected. Set to zero to disable.
|
||||||
CONFIG_SCHED_HAVE_PARENT - Remember the ID of the parent thread
|
CONFIG_SCHED_HAVE_PARENT - Remember the ID of the parent task
|
||||||
when a new child thread is created. This support enables some
|
when a new child task is created. This support enables some
|
||||||
additional features (such as SIGCHLD) and modifies the behavior
|
additional features (such as SIGCHLD) and modifies the behavior
|
||||||
of other interfaces. For example, it makes waitpid() more
|
of other interfaces. For example, it makes waitpid() more
|
||||||
standards complete by restricting the waited-for tasks to the
|
standards complete by restricting the waited-for tasks to the
|
||||||
children of the caller. Default: disabled.
|
children of the caller. Default: disabled.
|
||||||
|
CONFIG_SCHED_CHILD_STATUS
|
||||||
|
If this option is selected, then the exit status of the child task
|
||||||
|
will be retained after the child task exits. This option should be
|
||||||
|
selected if you require knowledge of a child process' exit status.
|
||||||
|
Without this setting, wait(), waitpid() or waitid() may fail. For
|
||||||
|
example, if you do:
|
||||||
|
|
||||||
|
1) Start child task
|
||||||
|
2) Wait for exit status (using wait(), waitpid(), or waitid()).
|
||||||
|
|
||||||
|
This can fail because the child task may run to completion before
|
||||||
|
the wait begins. There is a non-standard work-around in this case:
|
||||||
|
The above sequence will work if you disable pre-emption using
|
||||||
|
sched_lock() prior to starting the child task, then re-enable pre-
|
||||||
|
emption with sched_unlock() after the wait completes. This works
|
||||||
|
because the child task is not permitted to run until the wait is in
|
||||||
|
place.
|
||||||
|
|
||||||
|
The standard solution would be to enable CONFIG_SCHED_CHILD_STATUS. In
|
||||||
|
this case the exit status of the child task is retained after the
|
||||||
|
child exits and the wait will successful obtain the child task's
|
||||||
|
exit status whether it is called before the child task exits or not.
|
||||||
|
|
||||||
|
Warning: If you enable this feature, then your application must
|
||||||
|
either (1) take responsibility for reaping the child status with wait(),
|
||||||
|
waitpid(), or waitid(), or (2) suppress retention of child status.
|
||||||
|
If you do not reap the child status, then you have a memory leak and
|
||||||
|
your system will eventually fail.
|
||||||
|
|
||||||
|
Retention of child status can be suppressed on the parent using logic like:
|
||||||
|
|
||||||
|
struct sigaction sa;
|
||||||
|
|
||||||
|
sa.sa_handler = SIG_IGN;
|
||||||
|
sa.sa_flags = SA_NOCLDWAIT;
|
||||||
|
int ret = sigaction(SIGCHLD, &sa, NULL);
|
||||||
|
|
||||||
|
CONFIG_PREALLOC_CHILDSTATUS
|
||||||
|
To prevent runaway child status allocations and to improve
|
||||||
|
allocation performance, child task exit status structures are pre-
|
||||||
|
allocated when the system boots. This setting determines the number
|
||||||
|
of child status structures that will be pre-allocated. If this
|
||||||
|
setting is not defined or if it is defined to be zero then a value
|
||||||
|
of 2*MAX_TASKS is used.
|
||||||
|
|
||||||
|
Note that there cannot be more that CONFIG_MAX_TASKS tasks in total.
|
||||||
|
However, the number of child status structures may need to be
|
||||||
|
significantly larger because this number includes the maximum number
|
||||||
|
of tasks that are running PLUS the number of tasks that have exit'ed
|
||||||
|
without having their exit status reaped (via wait(), waitid(), or
|
||||||
|
waitpid()).
|
||||||
|
|
||||||
|
Obviously, if tasks spawn children indefinitely and never have the
|
||||||
|
exit status reaped, then you may have a memory leak! If you enable
|
||||||
|
the SCHED_CHILD_STATUS feature, then your application must take
|
||||||
|
responsibility for either (1) reaping the child status with wait(),
|
||||||
|
waitpid(), or waitid() or it must (2) suppress retention of child
|
||||||
|
status. Otherwise, your system will eventually fail.
|
||||||
|
|
||||||
|
Retention of child status can be suppressed on the parent using logic like:
|
||||||
|
|
||||||
|
struct sigaction sa;
|
||||||
|
|
||||||
|
sa.sa_handler = SIG_IGN;
|
||||||
|
sa.sa_flags = SA_NOCLDWAIT;
|
||||||
|
int ret = sigaction(SIGCHLD, &sa, NULL);
|
||||||
|
|
||||||
CONFIG_START_YEAR, CONFIG_START_MONTH, CONFIG_START_DAY -
|
CONFIG_START_YEAR, CONFIG_START_MONTH, CONFIG_START_DAY -
|
||||||
Used to initialize the internal time logic.
|
Used to initialize the internal time logic.
|
||||||
CONFIG_GREGORIAN_TIME - Enables Gregorian time conversions.
|
CONFIG_GREGORIAN_TIME - Enables Gregorian time conversions.
|
||||||
|
|||||||
@@ -82,10 +82,15 @@ CONFIG_BOARD_LOOPSPERMSEC=100
|
|||||||
# CONFIG_SIM_M32 is not set
|
# CONFIG_SIM_M32 is not set
|
||||||
# CONFIG_SIM_WALLTIME is not set
|
# CONFIG_SIM_WALLTIME is not set
|
||||||
|
|
||||||
|
#
|
||||||
|
# External Memory Configuration
|
||||||
|
#
|
||||||
|
|
||||||
#
|
#
|
||||||
# Architecture Options
|
# Architecture Options
|
||||||
#
|
#
|
||||||
# CONFIG_ARCH_NOINTC is not set
|
# CONFIG_ARCH_NOINTC is not set
|
||||||
|
# CONFIG_ARCH_VECNOTIRQ is not set
|
||||||
# CONFIG_ARCH_DMA is not set
|
# CONFIG_ARCH_DMA is not set
|
||||||
# CONFIG_ARCH_IRQPRIO is not set
|
# CONFIG_ARCH_IRQPRIO is not set
|
||||||
# CONFIG_CUSTOM_STACK is not set
|
# CONFIG_CUSTOM_STACK is not set
|
||||||
@@ -93,6 +98,7 @@ CONFIG_BOARD_LOOPSPERMSEC=100
|
|||||||
# CONFIG_ARCH_HAVE_VFORK is not set
|
# CONFIG_ARCH_HAVE_VFORK is not set
|
||||||
# CONFIG_ARCH_STACKDUMP is not set
|
# CONFIG_ARCH_STACKDUMP is not set
|
||||||
# CONFIG_ENDIAN_BIG is not set
|
# CONFIG_ENDIAN_BIG is not set
|
||||||
|
# CONFIG_ARCH_HAVE_RAMFUNCS is not set
|
||||||
|
|
||||||
#
|
#
|
||||||
# Board Settings
|
# Board Settings
|
||||||
@@ -132,6 +138,7 @@ CONFIG_RR_INTERVAL=0
|
|||||||
# CONFIG_SCHED_INSTRUMENTATION is not set
|
# CONFIG_SCHED_INSTRUMENTATION is not set
|
||||||
CONFIG_TASK_NAME_SIZE=32
|
CONFIG_TASK_NAME_SIZE=32
|
||||||
CONFIG_SCHED_HAVE_PARENT=y
|
CONFIG_SCHED_HAVE_PARENT=y
|
||||||
|
# CONFIG_SCHED_CHILD_STATUS is not set
|
||||||
# CONFIG_JULIAN_TIME is not set
|
# CONFIG_JULIAN_TIME is not set
|
||||||
CONFIG_START_YEAR=2007
|
CONFIG_START_YEAR=2007
|
||||||
CONFIG_START_MONTH=2
|
CONFIG_START_MONTH=2
|
||||||
@@ -242,8 +249,8 @@ CONFIG_SERIAL=y
|
|||||||
#
|
#
|
||||||
# File system configuration
|
# File system configuration
|
||||||
#
|
#
|
||||||
# CONFIG_FS_FAT is not set
|
|
||||||
# CONFIG_FS_RAMMAP is not set
|
# CONFIG_FS_RAMMAP is not set
|
||||||
|
# CONFIG_FS_FAT is not set
|
||||||
# CONFIG_FS_NXFFS is not set
|
# CONFIG_FS_NXFFS is not set
|
||||||
# CONFIG_FS_ROMFS is not set
|
# CONFIG_FS_ROMFS is not set
|
||||||
|
|
||||||
@@ -271,6 +278,7 @@ CONFIG_MM_REGIONS=1
|
|||||||
# CONFIG_BINFMT_EXEPATH is not set
|
# CONFIG_BINFMT_EXEPATH is not set
|
||||||
# CONFIG_NXFLAT is not set
|
# CONFIG_NXFLAT is not set
|
||||||
# CONFIG_ELF is not set
|
# CONFIG_ELF is not set
|
||||||
|
# CONFIG_BUILTIN is not set
|
||||||
# CONFIG_PIC is not set
|
# CONFIG_PIC is not set
|
||||||
# CONFIG_SYMTAB_ORDEREDBYNAME is not set
|
# CONFIG_SYMTAB_ORDEREDBYNAME is not set
|
||||||
|
|
||||||
@@ -318,7 +326,6 @@ CONFIG_LIB_SENDFILE_BUFSIZE=512
|
|||||||
#
|
#
|
||||||
# Built-In Applications
|
# Built-In Applications
|
||||||
#
|
#
|
||||||
# CONFIG_BUILTIN is not set
|
|
||||||
|
|
||||||
#
|
#
|
||||||
# Examples
|
# Examples
|
||||||
|
|||||||
Reference in New Issue
Block a user