Sponsored Content
Full Discussion: problem with signal()
Top Forums Programming problem with signal() Post 302145733 by narendra.pant on Thursday 15th of November 2007 04:34:47 AM
Old 11-15-2007
Error problem with signal()

#include<signal.h>
void suicide();
main()
{
printf("use CTRL \\ for exiting \n");
//signal(SIGINT,SIG_DFL);
signal(SIGQUIT,suicide);
for (;Smilie;
}

void suicide()
{ printf("hello here you r in the suicide code ");
}




i was just starting with signals .. and tried this ,, but in the above i am calling suicide function in the signal function , its not working why ??
also the default behavior of the <ctrl \ > is being suppressed .

can you tell me why it is so ,,
and when i tried it passing SIG_DFL it worked ..
 

10 More Discussions You Might Find Interesting

1. Programming

[Problem] raise a signal in FreeBSD

I am trying to send a SIGUSR1 to a set of process. Please tell me how to do. I've tried the system call raise(int sig) but it just raise a signal of to the 'current process.' My program is about a network chat server. When a client connects in, The main process will fork a new process... (1 Reply)
Discussion started by: Namely
1 Replies

2. UNIX for Advanced & Expert Users

I have a problem using signal SIGUSR2

hi I have created a application which uses SIGUSR2. It send this signal to server and waits for signal SIGUSR2 from server after server performing some operation server sends SIGUSR2 back to the application. The application then quits. This works fine which ran from terminal , but when I... (3 Replies)
Discussion started by: khan_069
3 Replies

3. Programming

Signal Problem

I am using the signal function, and passing it a function named quit procedure...I get the following warning.... passing arg2 of signal from incompatible pointer type... void quit_procedure(void); //this is the way i define my prototype... signal(SIGINT, quit_procedure); Please guide... (5 Replies)
Discussion started by: jacques83
5 Replies

4. Programming

problem in SIGSEGV signal handling

i wrote handler for sigsegv such that i can allocate memory for a variable to which sigsegv generated for illlegal acces of memory. my code is #include <signal.h> #include<stdio.h> #include<stdlib.h> #include<string.h> char *j; void segv_handler(int dummy) { j=(char *)malloc(10); ... (4 Replies)
Discussion started by: pavan6754
4 Replies

5. Programming

problem in reforking and signal handling

hi friends i have a problem in signal handling ... let me explain my problem clearly.. i have four process .. main process forks two child process and each child process again forks another new process respectively... the problem is whenever i kill the child process it is reforking and the... (2 Replies)
Discussion started by: senvenugopal
2 Replies

6. Shell Programming and Scripting

Tricky little problem, send signal to other machine without user

Hi everyone! I want to be able to send a signal to another machine on the same network, and have it trigger a script on that machine. Here's the reason why I can't just ssh: I don't have a username on that machine, but there is a user that is always logged on that I can do stuff on. So, I want... (5 Replies)
Discussion started by: declannalced
5 Replies

7. Programming

UNIX signal problem

Hi all, Sorry about the title,at first i decided to ask a problem about the signal mechanism,however,i'm now figured it out.Sorry to forget modify the title:wall:.I had a small problem that if i use the code which is commented,the code would get a segment fault,while the above code NOT.what's... (4 Replies)
Discussion started by: homeboy
4 Replies

8. Programming

problem in doing coding of signal handler

i m unble to execute code of signal handler using a) Wait b) Waitpid (1 Reply)
Discussion started by: madhura
1 Replies

9. Programming

Losing signal problem

I'm newbie in UNIX programming, I have a problem with signals. I'm writing multithread program, where threads can die at any moment. When thread dies it generates signal SIGUSR1 to main thread and then thread dies. Main thread gets a signal and waits for thread dead. I wrote program like this: ... (5 Replies)
Discussion started by: DendyGamer
5 Replies

10. Linux

Problem with dovecot (Killed with signal 15)

hey, i have been facing a very fatel error with dovecot.. i am getting this error in my dovecot.log file dovecot: Feb 13 15:21:02 Fatal: chdir(/var/mail/folders/user1) failed with uid 1001: Permission denied dovecot: Feb 13 15:21:02 Error: child 18732 (imap) returned error 89 dovecot: Feb... (3 Replies)
Discussion started by: htshshrm2
3 Replies
sigwait(2)							   System Calls 							sigwait(2)

NAME
sigwait - wait until a signal is posted SYNOPSIS
#include <signal.h> int sigwait(sigset_t *set); Standard conforming cc [ flag ... ] file ... -D_POSIX_PTHREAD_SEMANTICS [ library...] #include <signal.h> int sigwait(const sigset_t *set, int *sig); DESCRIPTION
The sigwait() function selects a signal in set that is pending on the calling thread (see thr_create(3C) and pthread_create(3C).) If no signal in set is pending, sigwait() blocks until a signal in set becomes pending. The selected signal is cleared from the set of signals pending on the calling thread and the number of the signal is returned, or in the standard-conforming version (see standards(5)) placed in sig. The selection of a signal in set is independent of the signal mask of the calling thread. This means a thread can synchronously wait for signals that are being blocked by the signal mask of the calling thread . To ensure that only the caller receives the signals defined in set, all threads should have signals in set masked including the calling thread. If the set argument points to an invalid address, the behavior is undefined and errno may be set to EFAULT. If sigwait() is called on an ignored signal, then the occurrence of the signal will be ignored, unless sigaction() changes the disposition. If more than one thread waits for the same signal, only one is unblocked when the signal arrives. RETURN VALUES
Upon successful completion, the default version of sigwait() returns a signal number; the standard-conforming version returns 0 and stores the received signal number at the location pointed to by sig. Otherwise, -1 is returned and errno is set to indicate an error. ERRORS
The sigwait() function will fail if: EINTR The wait was interrupted by an unblocked, caught signal. EINVAL The set argument contains an unsupported signal number. The sigwait() function may fail if: EFAULT The set argument points to an invalid address. EXAMPLES
Example 1 Creating a thread to handle receipt of a signal The following sample C code creates a thread to handle the receipt of a signal. More specifically, it catches the asynchronously generated signal, SIGINT. /******************************************************************** * * compile with -D_POSIX_PTHREAD_SEMANTICS switch; * required by sigwait() * * sigint thread handles delivery of signal. uses sigwait() to wait * for SIGINT signal. * ********************************************************************/ #include <pthread.h> #include <stdlib.h> #include <stdio.h> #include <string.h> #include <unistd.h> #include <signal.h> #include <synch.h> static void *threadTwo(void *); static void *threadThree(void *); static void *sigint(void *); sigset_t signalSet; void * main(void) { pthread_t t; pthread_t t2; pthread_t t3; sigfillset ( &signalSet ); /* * Block signals in initial thread. New threads will * inherit this signal mask. */ pthread_sigmask ( SIG_BLOCK, &signalSet, NULL ); printf("Creating threads "); pthread_create(&t, NULL, sigint, NULL); pthread_create(&t2, NULL, threadTwo, NULL); pthread_create(&t3, NULL, threadThree, NULL); printf("################## "); printf("press CTRL-C to deliver SIGINT to sigint thread "); printf("################## "); pthread_exit((void *)0); } static void * threadTwo(void *arg) { printf("hello world, from threadTwo [tid: %d] ", pthread_self()); printf("threadTwo [tid: %d] is now complete and exiting ", pthread_self()); pthread_exit((void *)0); } static void * threadThree(void *arg) { printf("hello world, from threadThree [tid: %d] ", pthread_self()); printf("threadThree [tid: %d] is now complete and exiting ", pthread_self()); pthread_exit((void *)0); } void * sigint(void *arg) { int sig; int err; printf("thread sigint [tid: %d] awaiting SIGINT ", pthread_self()); /* /* use standard-conforming sigwait() -- 2 args: signal set, signum */ err = sigwait ( &signalSet, &sig ); /* test for SIGINT; could catch other signals */ if (err || sig != SIGINT) abort(); printf(" SIGINT signal %d caught by sigint thread [tid: %d] ", sig, pthread_self()); pthread_exit((void *)0); } ATTRIBUTES
See attributes(5) for descriptions of the following attributes: +-----------------------------+-----------------------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | +-----------------------------+-----------------------------+ |Interface Stability |Standard | +-----------------------------+-----------------------------+ |MT-Level |Async-Signal-Safe | +-----------------------------+-----------------------------+ SEE ALSO
sigaction(2), signal.h(3HEAD), sigpending(2), sigprocmask(2), sigsuspend(2), pthread_create(3C), pthread_sigmask(3C), thr_create(3C), thr_sigsetmask(3C), attributes(5), standards(5) NOTES
The sigwait() function cannot be used to wait for signals that cannot be caught (see sigaction(2)). This restriction is silently imposed by the system. Solaris 2.4 and earlier releases provided a sigwait() facility as specified in POSIX.1c Draft 6. The final POSIX.1c standard changed the interface as described above. Support for the Draft 6 interface is provided for compatibility only and may not be supported in future releases. New applications and libraries should use the standard-conforming interface. SunOS 5.11 24 Jun 2002 sigwait(2)
All times are GMT -4. The time now is 04:13 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy