LinuxQuestions.org
Latest LQ Deal: Linux Power User Bundle
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 06-22-2009, 04:03 AM   #1
arunpk
LQ Newbie
 
Registered: Jun 2009
Posts: 3

Rep: Reputation: 0
Smile 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 .

Last edited by arunpk; 06-22-2009 at 04:04 AM.
 
Old 06-22-2009, 08:29 AM   #2
jf.argentino
Member
 
Registered: Apr 2008
Location: Toulon (France)
Distribution: FEDORA CORE
Posts: 493

Rep: Reputation: 50
If you want to wait for a thread to end, use "pthread_join"
 
Old 06-29-2009, 08:20 AM   #3
arunpk
LQ Newbie
 
Registered: Jun 2009
Posts: 3

Original Poster
Rep: Reputation: 0
thread monitore

Quote:
Originally Posted by jf.argentino View Post
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
 
Old 06-29-2009, 09:38 AM   #4
jf.argentino
Member
 
Registered: Apr 2008
Location: Toulon (France)
Distribution: FEDORA CORE
Posts: 493

Rep: Reputation: 50
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...
 
Old 06-29-2009, 09:24 PM   #5
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.8, Centos 5.10
Posts: 17,240

Rep: Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324
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.
 
Old 06-30-2009, 08:58 AM   #6
arunpk
LQ Newbie
 
Registered: Jun 2009
Posts: 3

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by chrism01 View Post
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.
*******************************************************
 
Old 07-01-2009, 02:31 AM   #7
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.8, Centos 5.10
Posts: 17,240

Rep: Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324
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.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Thread Scheduling using POSIX THREAD rameshtekumudi Programming 3 09-01-2006 11:47 AM
POSIX thread Programming msriram_linux Programming 4 11-21-2004 04:14 PM
POSIX thread Ivan Lee Programming 2 03-28-2003 04:54 AM
RT Posix thread permissions spaceape Programming 0 01-23-2003 09:50 AM
posix thread sulo Programming 1 02-28-2002 08:41 PM


All times are GMT -5. The time now is 01:52 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration