Sponsored Content
Top Forums Programming How to implement SIGKILL and SIGTERM and print a message? Post 302144795 by porter on Friday 9th of November 2007 08:01:14 PM
Old 11-09-2007
1. Both sigaction and signal install signal handlers,

(a) don't use both in the same program,
(b) sigaction is the posix one, use that.
(c) With sigaction you don't need to reinstall the signal handler.

2. atexit installs another callback function, so when the program exits politely, through a call to exit you code will get called so you can tidy up.

3. only set flags in the signal handlers, don't do 'work'.

4. you have done sigfillset but done nothing with the sigset_t, you need to call sigprocmask to block or unblock those signals.

5. to ignore a signal, you can

(a) either use SIG_IGN as the callback
(b) or simply block it so it is never delivered to your program.
(c) or get it to call an empty signal handler function

6. compile with maximum warnings, if you are using gcc use "-Wall -Werror", that would have caught your "atexit".

7. And as mentioned, you can't catch SIGKILL, the kernel will just evaporate your process.
 

10 More Discussions You Might Find Interesting

1. Programming

signals - SIGTERM

Hi all, I need some urgent help. we are using Dynix/ptx V4.5 on i386, have several processes and instances are running on the box round the clock.we increased the processes recently. We have coded to handle the signals in our programs. Recently, we noticed most of our processes are... (2 Replies)
Discussion started by: reddyb
2 Replies

2. Shell Programming and Scripting

Why SIGKILL will occur?

Hi Gurus, I am executing my Datastage jobs on UNIX operating System. While running the jobs i am getting the following error: main_program: Unexpected termination by Unix signal 9(SIGKILL) Can any one please let me know what are the possible situations where this SIGKILL will arrise? ... (9 Replies)
Discussion started by: choppas
9 Replies

3. Solaris

To print Coloured Prelogin Message on SOLARIS--9................

Hiiii..... Every one...... I am using /etc/issue file to display Pre-login Message on my system, installed with SOLARIS-9. I am getting this Message in White fonts having Black background ( Colour of the Screen)..... So, is there ... (2 Replies)
Discussion started by: prashantshukla
2 Replies

4. Shell Programming and Scripting

Error while trying to print message

Hi all Geting this error while trying to print message as : ./logfunc: print: bad file unit number heres what i m trying to do : log_date="$(date '+%d/%m/%Y %H:%M:%S')" log_type="Message" print "${log_date}: ${log_type}" print -u3 "${log_date}: ${log_type}" this error is due to... (3 Replies)
Discussion started by: Navatha
3 Replies

5. Shell Programming and Scripting

Print a message at specific line on prompt

Hi Friends, I am using HP-UNIX(ksh). I want to print a message at specific line on the prompt screen. For Example: for num in 1 10 3 145 do echo $num // need to print this on the same line for each number sleep 2 done Actual Output: ========== 1 10 3 145 Expected Output:... (5 Replies)
Discussion started by: Niroj
5 Replies

6. Solaris

SIGQUIT and SIGKILL message

Dear All, I have machine with SunOS 5.10 Generic_138888-01 sun4v sparc SUNW,SPARC-Enterprise-T5120. Yesterday there is something at dmesg command : May 25 18:09:02 cacao_launcher: Timeout occured on heartbeat channel, cleanup engaged May 25 18:09:07 cacao_launcher: watchdog : warning,... (0 Replies)
Discussion started by: mbah_jiman
0 Replies

7. Shell Programming and Scripting

How to detect SIGTERM,SIGKILL signal in UNIX

Dear All We have JBOSS server running on Linux we need to track Graceful Shutdown(SIGTERM) and Forceful Shutdown(SIGKILL) timestamp and write it into one file, I am new to UNIX Signal processing if is it possible how to detect it? We generally do $kill PID For Graceful... (5 Replies)
Discussion started by: mnmonu
5 Replies

8. Shell Programming and Scripting

SIGSTOP and SIGKILL

Which is sent to a terminal when it closes? SIGKILL? Reason I ask is I have a script I want to run in the background, but want it to run even if the terminal window is closed. Or, I'd like it to background itself if the terminal is closed but not if its running in an open window. I will learn how... (5 Replies)
Discussion started by: DC Slick
5 Replies

9. UNIX for Advanced & Expert Users

Print message while using sqlplus

I want to connect to oracle database from solaris... After that i will drop and create a no.of tables.One of the table example is as below. sqlplus -s usrname/password@dbname << SQL >> $logfile 2>&1 echo " dropping the table1" | tee logfile DROP TABLE Table1 echo "creating the table1" |... (1 Reply)
Discussion started by: millan
1 Replies

10. Shell Programming and Scripting

Script to check the string in a file and print an attribute in the message

Hi, I am new to shell scripting and got a task to complete. Task is : we have a log file where in i need to traverse through the whole file to check the string "Person Type missing in message" and after that i need to get EMPLID=xxxxxx from the file and print details in a different file. ... (1 Reply)
Discussion started by: suren424
1 Replies
PTHREAD_SIGNAL(3)					     Library Functions Manual						 PTHREAD_SIGNAL(3)

NAME
pthread_sigmask, pthread_kill, sigwait - handling of signals in threads SYNOPSIS
#include <pthread.h> #include <signal.h> int pthread_sigmask(int how, const sigset_t *newmask, sigset_t *oldmask); int pthread_kill(pthread_t thread, int signo); int sigwait(const sigset_t *set, int *sig); DESCRIPTION
pthread_sigmask changes the signal mask for the calling thread as described by the how and newmask arguments. If oldmask is not NULL, the previous signal mask is stored in the location pointed to by oldmask. The meaning of the how and newmask arguments is the same as for sigprocmask(2). If how is SIG_SETMASK, the signal mask is set to newmask. If how is SIG_BLOCK, the signals specified to newmask are added to the current signal mask. If how is SIG_UNBLOCK, the signals specified to newmask are removed from the current signal mask. Recall that signal masks are set on a per-thread basis, but signal actions and signal handlers, as set with sigaction(2), are shared between all threads. pthread_kill send signal number signo to the thread thread. The signal is delivered and handled as described in kill(2). sigwait suspends the calling thread until one of the signals in set is delivered to the calling thread. It then stores the number of the signal received in the location pointed to by sig and returns. The signals in set must be blocked and not ignored on entrance to sigwait. If the delivered signal has a signal handler function attached, that function is not called. CANCELLATION
sigwait is a cancellation point. RETURN VALUE
On success, 0 is returned. On failure, a non-zero error code is returned. ERRORS
The pthread_sigmask function returns the following error codes on error: EINVAL how is not one of SIG_SETMASK, SIG_BLOCK, or SIG_UNBLOCK EFAULT newmask or oldmask point to invalid addresses The pthread_kill function returns the following error codes on error: EINVAL signo is not a valid signal number ESRCH the thread thread does not exist (e.g. it has already terminated) The sigwait function never returns an error. AUTHOR
Xavier Leroy <Xavier.Leroy@inria.fr> SEE ALSO
sigprocmask(2), kill(2), sigaction(2), sigsuspend(2). NOTES
For sigwait to work reliably, the signals being waited for must be blocked in all threads, not only in the calling thread, since otherwise the POSIX semantics for signal delivery do not guarantee that it's the thread doing the sigwait that will receive the signal. The best way to achieve this is block those signals before any threads are created, and never unblock them in the program other than by calling sigwait. BUGS
Signal handling in LinuxThreads departs significantly from the POSIX standard. According to the standard, ``asynchronous'' (external) sig- nals are addressed to the whole process (the collection of all threads), which then delivers them to one particular thread. The thread that actually receives the signal is any thread that does not currently block the signal. In LinuxThreads, each thread is actually a kernel process with its own PID, so external signals are always directed to one particular thread. If, for instance, another thread is blocked in sigwait on that signal, it will not be restarted. The LinuxThreads implementation of sigwait installs dummy signal handlers for the signals in set for the duration of the wait. Since signal handlers are shared between all threads, other threads must not attach their own signal handlers to these signals, or alternatively they should all block these signals (which is recommended anyway -- see the Notes section). LinuxThreads PTHREAD_SIGNAL(3)
All times are GMT -4. The time now is 10:38 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy