LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   posix thread status monitor (https://www.linuxquestions.org/questions/linux-newbie-8/posix-thread-status-monitor-734699/)

arunpk 06-22-2009 03:03 AM

posix thread status monitor
 
dear All
can any body tells me how can i continually poll(monitor) the status of the all threads created by the main process .

jf.argentino 06-22-2009 07:29 AM

If you want to wait for a thread to end, use "pthread_join"

arunpk 06-29-2009 07:20 AM

thread monitore
 
Quote:

Originally Posted by jf.argentino (Post 3582226)
If you want to wait for a thread to end, use "pthread_join"

I cannot use the thread join.because for me , 5 thread should run continually in round robin manner .a separate thread (Lets say 6 th thread )will monitor the status of all other 5 threads periodically

jf.argentino 06-29-2009 08:38 AM

Two quick ideas i've got without thinking too much...

You can use a monitor thread that listen (sigwait) to signals emitted by the threads you it monitors (pthread_kill), one signal per thread to monitor but I'm not sure if you can set a timeout to the "sigwait" to detect the signal missing and then the thread's dead.

Or you could share an array of int between the monitor and each thread, each thread when starting, set its own var to 1, and reset it to 0 when ending (take a look at pthread_cleanup_push / pthread_cleanup_pop could help). The the monitor thread periodically read each value to know the threads status...

chrism01 06-29-2009 08:24 PM

When I was reading up on threads, they said not to mix signals and threads, not least because thrs are lightweight processes inside the one process env (as of 2.6 kernels).
Use thr globals vars, as per 2nd suggestion above.

arunpk 06-30-2009 07:58 AM

Quote:

Originally Posted by chrism01 (Post 3590822)
When I was reading up on threads, they said not to mix signals and threads, not least because thrs are lightweight processes inside the one process env (as of 2.6 kernels).
Use thr globals vars, as per 2nd suggestion above.

Thanks for the quick response .
All my 5 thread will run in endless loop (like task).so witting 1 for starting and 0 during end cannot work.
i planing 3 ideas plz let me know the your comments
****************************************************************
1) Thread 6 will send ping request (can call send Alive message ) to all thread using Posix message queue , and then wait for the response (Non Blocking call to read the queue).As soon as each thread (1 to 5)got the request they will prepare a response message and send to task 6 queue (response message will contain the thread ID , in order identify which thread is responded ).thread 6 will read the q
if any one thread is not responding thread 6 will retry or take necessary action .
The above steps will do periodically by thread 6.
*****************************************************************
2) using signal , thread 6 will send signal to other threads , Each threads having the signal handler ,. As soon as the handler is invoked threads (1-5) will be send response signal to thread 6 thread 6 will collect response signal and verify who is not responded and take necessary action for that
****************************************************************
3) using a global Array
int sendAliveMsg[NO_OF_THREAD];//global array
Thread 6 will make all position in the array (sendAliveMsg) to 0.
if threads [1-5] found their location is 0 zero will make it 1
periodically thread 6 will read the array and check status is 1 .if status is 1 it will make to 0. if any thread is running properly it cannot reset the global array.
*******************************************************

chrism01 07-01-2009 01:31 AM

Go with 3.
2 isn't good becuase you can only send a signal to a process (pid), not a thread.
The one Linux process contains all the threads, and its pure luck which thread picks up the signal.
There's no way to ensure that a given thr (eg say num 4) will ever see a signal, even if you send it a 100 times.


All times are GMT -5. The time now is 11:46 AM.