kill now sends the signal to the main thread of a process only. To target a specific thread use the new send_signal syscall. Also added set_alarm.

git-svn-id: file:///srv/svn/repos/haiku/trunk/current@1662 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
lillo
2002-10-25 22:36:08 +00:00
parent 617c98ba68
commit 9870ddcea7
8 changed files with 112 additions and 11 deletions
+43 -9
View File
@@ -11,8 +11,10 @@
void sig_handler(int);
void install_handler(int);
void alarm_handler(int);
void install_handler(int, __signal_func_ptr);
int32 thread(void *);
void usage(void);
void
@@ -29,14 +31,21 @@ sig_handler(int sig)
void
install_handler(int sig)
alarm_handler(int sig)
{
printf("Alarm!\n");
}
void
install_handler(int sig, __signal_func_ptr handler)
{
struct sigaction newa;
struct sigaction olda;
memset(&newa, 0, sizeof(newa));
newa.sa_handler = sig_handler;
newa.sa_handler = handler;
newa.sa_flags = SA_NOMASK | SA_RESTART;
if (sys_sigaction(sig, &newa, &olda) < 0) {
@@ -57,17 +66,42 @@ thread(void *data)
}
void
usage()
{
printf("usage: sig_test <mode>\n"
"where `mode' is one of:\n"
"\t1\tInstalls one handler for all signals\n"
"\t2\tSame as 1 but also spawns 5 threads with no active handlers\n"
"\t3\tSets an alarm via set_alarm\n"
"\n");
exit(1);
}
int
main(int argc, char **argv)
{
int i;
printf("Installing signal handlers...\n");
for (i=1; i<=NSIG; i++)
install_handler(i);
printf("Spawning some threads...\n");
for (i=0; i<5; i++)
resume_thread(spawn_thread(thread, "sig_test aux thread", B_NORMAL_PRIORITY, NULL));
if (argc != 2)
usage();
switch (argv[1][0]) {
case '1':
printf("Spawning some threads...\n");
for (i=0; i<5; i++)
resume_thread(spawn_thread(thread, "sig_test aux thread", B_NORMAL_PRIORITY, NULL));
case '2':
printf("Installing signal handlers...\n");
for (i=1; i<=NSIG; i++)
install_handler(i, sig_handler);
break;
case '3':
install_handler(SIGALRM, alarm_handler);
sys_set_alarm(5000000, B_PERIODIC_ALARM);
break;
}
printf("Done. Entering sleep mode...\n");
while (1) {
if (sys_snooze(1000000000L) == B_INTERRUPTED)