Sponsored Content
Full Discussion: Killing a Child Thread
Top Forums Programming Killing a Child Thread Post 302648705 by Brandon9000 on Wednesday 30th of May 2012 09:14:20 AM
Old 05-30-2012
Thanks, but what do you mean by "read cancellation point?"

One other matter, my tests show that if, by chance, the thread no longer exists when I call pthread_cancel, the parent will abend with a segfault. What signal might I trap with signal() to prevent this?
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

killing a child process within a shell

Hi All, I have a written a script in korn shell for importing data into a oracle database. The shell invokes the import within the script. I want to kill this import (child process) . I tries using trap, but this does not kill the import even if i press cnt c. i have to login into other terminal... (2 Replies)
Discussion started by: yerics
2 Replies

2. Shell Programming and Scripting

killing a child process

I am calling another script from my main script and making it run in the background,based upon the value of the input provided by the user I want to kill the child process ,I have written this code timer.ksh & PID=$$ print "\n Do you wish to continue .. (Y/N) : \c " read kill_proc if ]... (4 Replies)
Discussion started by: mervin2006
4 Replies

3. Shell Programming and Scripting

Killing child process in ksh

I have a script that (ideally) starts tcpdump, sleeps a given number of seconds, then kills it. When I do this for 10 seconds or and hour, it works fine. When I try it for 10 hours (the length I actually want) it just doesn't die, and will actually stick around for days. Relevant part of my... (1 Reply)
Discussion started by: upnix
1 Replies

4. UNIX for Advanced & Expert Users

killing all child processes

Hi, Is there a way I can kill all the child processes of a process, given its process id. Many thanks in advance. J. (1 Reply)
Discussion started by: superuser84
1 Replies

5. UNIX for Advanced & Expert Users

Child Killing Parent

Hi all, I am writing a script which calls other third party scripts that perform numerous actions. I have no control over these scripts. My problem is, one of these scripts seems to execute and do what it is meant to do, but my calling / parent script always exits at that point. I need to... (4 Replies)
Discussion started by: mark007
4 Replies

6. Solaris

Killing a thread having a listener socket

Hi All I have a separate thread ListenerThread having a socket listening to info broadcasted by some remote server. This is created in my main thread. Because of requirements, once the separate thread is started I need to avoid any blocking function on the main thread. Once it comes to the... (2 Replies)
Discussion started by: manustone
2 Replies

7. Red Hat

Killing child daemon started by parent process

Hi All, Hope this is right area to ask this question. I have a shell script (bash) "wrapper.sh", which contains few simple shell command which executes a "server.sh" (conatins code to execute a java server) as a daemon. Now what I want to kill this "server.sh" so that the server should... (2 Replies)
Discussion started by: jw_amp
2 Replies

8. Programming

Parent Thread Of Child Thread

Parent Thread Of Child Thread Suppose a process creates some threads say threadC and threadD. Later on each of these threads create new child threads say threadC1, threadC2, threadC3 etc. So a tree of threads will get created. Is there any way to find out the parent thread of one such... (1 Reply)
Discussion started by: rupeshkp728
1 Replies

9. Shell Programming and Scripting

A script that kills previous instances of itself upon running not killing child processes

I'm likely going to explain this clumsily, so apologies in advance: I have the following script: #!/bin/bash pidPrefix="logGen" checkPrime () { if /sbin/ifconfig eth0:0|/bin/grep -wq inet;then isPrime=1;else isPrime=0;fi } killScript () { /usr/bin/find /var/run -name... (4 Replies)
Discussion started by: DeCoTwc
4 Replies

10. Solaris

Child killing parent process and how to set up SMF

Hello, A little background on what we are doing first. We are running several applications from a CLI, and not all of them are fully functional. They do on occasion core dump, not a problem. We are running a service that takes a screen scrape of those apps and displays them in a more user... (5 Replies)
Discussion started by: Bryan.Eidson
5 Replies
PTHREAD_CANCEL(3)					     Library Functions Manual						 PTHREAD_CANCEL(3)

NAME
pthread_cancel, pthread_setcancelstate, pthread_setcanceltype, pthread_testcancel - thread cancellation SYNOPSIS
#include <pthread.h> int pthread_cancel(pthread_t thread); int pthread_setcancelstate(int state, int *oldstate); int pthread_setcanceltype(int type, int *oldtype); void pthread_testcancel(void); DESCRIPTION
Cancellation is the mechanism by which a thread can terminate the execution of another thread. More precisely, a thread can send a cancel- lation request to another thread. Depending on its settings, the target thread can then either ignore the request, honor it immediately, or defer it till it reaches a cancellation point. When a thread eventually honors a cancellation request, it performs as if pthread_exit(PTHREAD_CANCELED) has been called at that point: all cleanup handlers are executed in reverse order, finalization functions for thread-specific data are called, and finally the thread stops executing with the return value PTHREAD_CANCELED. See pthread_exit(3) for more information. pthread_cancel sends a cancellation request to the thread denoted by the thread argument. pthread_setcancelstate changes the cancellation state for the calling thread -- that is, whether cancellation requests are ignored or not. The state argument is the new cancellation state: either PTHREAD_CANCEL_ENABLE to enable cancellation, or PTHREAD_CANCEL_DISABLE to disable cancellation (cancellation requests are ignored). If oldstate is not NULL, the previous cancellation state is stored in the location pointed to by oldstate, and can thus be restored later by another call to pthread_setcancelstate. pthread_setcanceltype changes the type of responses to cancellation requests for the calling thread: asynchronous (immediate) or deferred. The type argument is the new cancellation type: either PTHREAD_CANCEL_ASYNCHRONOUS to cancel the calling thread as soon as the cancellation request is received, or PTHREAD_CANCEL_DEFERRED to keep the cancellation request pending until the next cancellation point. If oldtype is not NULL, the previous cancellation state is stored in the location pointed to by oldtype, and can thus be restored later by another call to pthread_setcanceltype. Threads are always created by pthread_create(3) with cancellation enabled and deferred. That is, the initial cancellation state is PTHREAD_CANCEL_ENABLE and the initial type is PTHREAD_CANCEL_DEFERRED. Cancellation points are those points in the program execution where a test for pending cancellation requests is performed and cancellation is executed if positive. The following POSIX threads functions are cancellation points: pthread_join(3) pthread_cond_wait(3) pthread_cond_timedwait(3) pthread_testcancel(3) sem_wait(3) sigwait(3) All other POSIX threads functions are guaranteed not to be cancellation points. That is, they never perform cancellation in deferred can- cellation mode. pthread_testcancel does nothing except testing for pending cancellation and executing it. Its purpose is to introduce explicit checks for cancellation in long sequences of code that do not call cancellation point functions otherwise. RETURN VALUE
pthread_cancel, pthread_setcancelstate and pthread_setcanceltype return 0 on success and a non-zero error code on error. ERRORS
pthread_cancel returns the following error code on error: ESRCH no thread could be found corresponding to that specified by the thread ID. pthread_setcancelstate returns the following error code on error: EINVAL the state argument is not PTHREAD_CANCEL_ENABLE nor PTHREAD_CANCEL_DISABLE pthread_setcanceltype returns the following error code on error: EINVAL the type argument is not PTHREAD_CANCEL_DEFERRED nor PTHREAD_CANCEL_ASYNCHRONOUS AUTHOR
Xavier Leroy <Xavier.Leroy@inria.fr> SEE ALSO
pthread_exit(3), pthread_cleanup_push(3), pthread_cleanup_pop(3). BUGS
POSIX specifies that a number of system calls (basically, all system calls that may block, such as read(2), write(2), wait(2), etc.) and library functions that may call these system calls (e.g. fprintf(3)) are cancellation points. LinuxThreads is not yet integrated enough with the C library to implement this, and thus none of the C library functions is a cancellation point. For system calls at least, there is a workaround. Cancellation requests are transmitted to the target thread by sending it a signal. That signal will interrupt all blocking system calls, causing them to return immediately with the EINTR error. So, checking for cancellation during a read system call, for instance, can be achieved as follows: pthread_testcancel(); retcode = read(fd, buffer, length); pthread_testcancel(); LinuxThreads PTHREAD_CANCEL(3)
All times are GMT -4. The time now is 01:27 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy