Sponsored Content
Top Forums UNIX for Advanced & Expert Users how to kill threads in solaris Post 302101980 by Perderabo on Saturday 6th of January 2007 06:07:14 PM
Old 01-06-2007
izy100, "kill" means "send a signal to". Signals get complicated real fast in a multi-threaded program. Best practice is for a multi-threaded process to have a dedicated signal acceptor thread (for lack of a better term) that has called sigwait. It then may invoke pthread_kill to signal some particular thread. Remember that if a thread who is not expecting a signal somehow gets one anyway, for the most part, one of two things will happen:

1. the signal will be ignored
2. the thread will behave as if it called exit(), thus destroying the entire process

In either case, it doesn't matter that much which thread was involved.

Threads cease to exist when they return from their main function or call pthread_exit. The thread is said to be cancelled. One thread can call pthread_cancel to try to cancel another thread. But threads may render themselves uncancelable. And processes rarely create superfluous or even expendable threads... in most cases, if one thread dies, the whole process must die with it.
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

kill scripts under Solaris

I should know this, but do K scripts in the /etc/rc?.d directories get run in numerically ascending or descending order? By default there are none in rc3.d. Is it OK to put 2 in there, and will they be run first (which is my goal). Thanks, Chuck (1 Reply)
Discussion started by: 98_1LE
1 Replies

2. UNIX for Advanced & Expert Users

When kill doesnt work, how to kill a process ?

Hi All, I am unable to kill a process using kill command. I am using HP-UX system. I have tried with kill -9 and i have root privilages. How can i terminate this daemon ? ? ? Regards, Vijay Hegde (3 Replies)
Discussion started by: VijayHegde
3 Replies

3. Programming

Can SIGTERM to main process kill the detached threads?

Hi, I am stuck up with a strange problem. I am writing an application - a kinda tracker that reads data from memcache and invokes theads to process each record of the memcache. I dont want to join all my threads because my tracker should poll the cache in regular intervals say sum 300... (2 Replies)
Discussion started by: deepti_v25
2 Replies

4. Shell Programming and Scripting

Kill a process without using kill command

Sorry, posted the question in other forum. (0 Replies)
Discussion started by: sudhamacs
0 Replies

5. Shell Programming and Scripting

Shell Script to Kill Process(number of process) Unix/Solaris

Hi Experts, we do have a shell script for Unix Solaris, which will kill all the process manullay, it used to work in my previous env, but now it is throwing this error.. could some one please help me to resolve it This is how we execute the script (and this is the requirement) ... (2 Replies)
Discussion started by: jonnyvic
2 Replies

6. Shell Programming and Scripting

Kill an specific process ID using the KILL and GREP commands

Good afternoon I need to KILL a process in a single command sentence, for example: kill -9 `ps -aef | grep 'CAL255.4ge' | grep -v grep | awk '{print $2}'` That sentence Kills the process ID corresponding to the program CAL255.4ge. However it is possible that the same program... (6 Replies)
Discussion started by: enriquegm82
6 Replies

7. Shell Programming and Scripting

How to start multiple threads in Solaris?

Hello, In a unix Solaris environment, (for simulation) how to start multiple threads (as Light Weight Process, not background process)? thanks, J. (7 Replies)
Discussion started by: seafan
7 Replies

8. UNIX for Advanced & Expert Users

How to kill a thread among several threads belongs to a process?

I would like to know is there any we can kill a single thread among multiple threads belongs to process? Since Signal action is process wise not per thread, i strongly feel that we can not or for that mater from external sources as well single thread can not be killed which is critical section... (2 Replies)
Discussion started by: murali242512
2 Replies

9. Solaris

Way to find source of a kill -9 in Solaris

Hello Guys, Someone or, some tool has killed the application process with signal 9 (kill -9) . How to track that in Solaris? On AIX we can use light-weight tool called ProbeVue to track it but not sure how to do it on Solaris. Appreciate your help. Kelly (3 Replies)
Discussion started by: aixusrsys
3 Replies

10. UNIX for Beginners Questions & Answers

Solaris, grant user to kill another process

the task is grant user1 to kill another (for example user2) process. My steps: by root: usermod -P "Process Management" user1 login user1 user1@server (~) pfexec kill <PID> the result is: ksh: <PID>: not found or user1@server (~) pfexec pkill <PID> the result: nothing happens, still... (0 Replies)
Discussion started by: dsyberia
0 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 05:47 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy