saeedeh1363
02-09-2007, 08:45
سلام.
دوستاي خوبم يه سوال داشتم اونم اينكه قطعه كد زير كه در رابطه با سيگنال هندلر هستش رو اگر در محيط eclipse لينوكس تايپ كنم دقيقا چه خروجي اي رو دريافت خواهم كرد.من بدليل مشكلاتي نتونستم لينوكس رو زوي سيستمم نصب كنم و نتيجه كد زير رو عملا مشاهده كنم.اگه بتونيد كمكم كنيد خيلي لطف كرديد.:20:
#include <signal.h>
#include <string.h>
#include <sys/types.h>
#include <sys/wait.h>
sig_atomic_t child_exit_status;
void clean_up_child_process (int signal_number)
{
/* Clean up the child process. */
int status;
wait (&status);
/* Store its exit status in a global variable. */
child_exit_status = status;
}
int main ()
{
/* Handle SIGCHLD by calling clean_up_child_process. */
struct sigaction sigchld_action;
memset (&sigchld_action, 0, sizeof (sigchld_action));
sigchld_action.sa_handler = &clean_up_child_process;
sigaction (SIGCHLD, &sigchld_action, NULL);
/* Now do things, including forking a child process. */
/* ... */
return 0;
}
Note how the signal handler stores the child process’s exit status in a global variable,
from which the main program can access it. Because the variable is assigned in a signal
handler, its type is sig_atomic_t.
دوستاي خوبم يه سوال داشتم اونم اينكه قطعه كد زير كه در رابطه با سيگنال هندلر هستش رو اگر در محيط eclipse لينوكس تايپ كنم دقيقا چه خروجي اي رو دريافت خواهم كرد.من بدليل مشكلاتي نتونستم لينوكس رو زوي سيستمم نصب كنم و نتيجه كد زير رو عملا مشاهده كنم.اگه بتونيد كمكم كنيد خيلي لطف كرديد.:20:
#include <signal.h>
#include <string.h>
#include <sys/types.h>
#include <sys/wait.h>
sig_atomic_t child_exit_status;
void clean_up_child_process (int signal_number)
{
/* Clean up the child process. */
int status;
wait (&status);
/* Store its exit status in a global variable. */
child_exit_status = status;
}
int main ()
{
/* Handle SIGCHLD by calling clean_up_child_process. */
struct sigaction sigchld_action;
memset (&sigchld_action, 0, sizeof (sigchld_action));
sigchld_action.sa_handler = &clean_up_child_process;
sigaction (SIGCHLD, &sigchld_action, NULL);
/* Now do things, including forking a child process. */
/* ... */
return 0;
}
Note how the signal handler stores the child process’s exit status in a global variable,
from which the main program can access it. Because the variable is assigned in a signal
handler, its type is sig_atomic_t.