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 04-02-2015, 11:21 AM   #1
YehudaSinger
LQ Newbie
 
Registered: Jun 2013
Posts: 23

Rep: Reputation: Disabled
Monitoring the execution of POSIX threads


I work on Red-Hat Enterprice OS.
I run one process which generates many POSIX threads.
How can I monitor/trace their execution.

Best regards,
Yehuda
 
Old 04-02-2015, 05:14 PM   #2
Pearlseattle
Member
 
Registered: Aug 2007
Location: Zurich, Switzerland
Distribution: Gentoo
Posts: 934

Rep: Reputation: 104Reputation: 104
Please elaborate - so far I would say that you monitor them like any other process/thread.
 
Old 04-05-2015, 05:30 AM   #3
YehudaSinger
LQ Newbie
 
Registered: Jun 2013
Posts: 23

Original Poster
Rep: Reputation: Disabled
Dear Pearlseattle
First of all, thanks for your response.

We have a program which creates many threads. I want to monitor the threads. The threads are POSIX using pthread library.
The utilities ps, mpstat, iostat give information on the process level.

Best regards,
Yehuda
 
Old 04-05-2015, 03:15 PM   #4
Pearlseattle
Member
 
Registered: Aug 2007
Location: Zurich, Switzerland
Distribution: Gentoo
Posts: 934

Rep: Reputation: 104Reputation: 104
Hi
I might be wrong (anybody wants to comment?) but such threads are handled the same way as processes - meaning that if your run e.g. htop (or ps, etc...) and you spawn a thread, you'll see it running with its own PID (different from the parent process).
 
Old 04-05-2015, 06:24 PM   #5
millgates
Member
 
Registered: Feb 2009
Location: 192.168.x.x
Distribution: Slackware
Posts: 840

Rep: Reputation: 380Reputation: 380Reputation: 380Reputation: 380
from man ps:
Code:
THREAD DISPLAY
H               Show threads as if they were processes

-L              Show threads, possibly with LWP and NLWP columns

-T              Show threads, possibly with SPID column

m               Show threads after processes

-m              Show threads after processes
Also, practically everything you would ever want to know about a particular thread can be found in files under /proc/[PID]/task/[TID].
 
Old 04-06-2015, 05:45 AM   #6
YehudaSinger
LQ Newbie
 
Registered: Jun 2013
Posts: 23

Original Poster
Rep: Reputation: Disabled
More information

Dear Millgates
Thanks for your answer.
Indeed top gives me the threads but the TID is not part of the information. Instead, I get a different PID for each POSIX therad.
Is there a way to get the TID also?

The information related to the thread is very interesting. How to get either he TID or the thread name while execution. We ran the top and ps utilities as a child process to the main process running the threads and record he information.
Thanks,
Yehuda

Last edited by YehudaSinger; 04-06-2015 at 06:11 AM.
 
Old 04-06-2015, 08:46 AM   #7
millgates
Member
 
Registered: Feb 2009
Location: 192.168.x.x
Distribution: Slackware
Posts: 840

Rep: Reputation: 380Reputation: 380Reputation: 380Reputation: 380
Quote:
Originally Posted by YehudaSinger View Post
TID is not part of the information. Instead, I get a different PID for each POSIX therad.
Is there a way to get the TID also?
The individual threads of a single process should share the PID. If you see different ID's for the threads, then those are TID, not PID.

That said, you can customize the output of ps, for example:

Code:
ps -L -o pid,tid,comm
  PID   TID COMMAND
  798   798 bash
 1699  1699 testprog
 1699  1700 testprog
 1699  1701 testprog
 1699  1702 testprog
 1699  1703 testprog
 1699  1704 testprog
 1699  1705 testprog
 1699  1706 testprog
 1709  1709 ps
 
Old 04-07-2015, 08:15 AM   #8
YehudaSinger
LQ Newbie
 
Registered: Jun 2013
Posts: 23

Original Poster
Rep: Reputation: Disabled
Final Summary

Dear Millgates
Thanks for your answer. here are my remarks:
1, The TID is not the thread ID which is obtained either during the creation or by the thread_self)_'
2. The TID is obtained by the system call gettid(). This function is not in the libc. Hence, we call it by the following sequence: syscall(SYS_gettid) ;


Thanks.
Yehuda
 
  


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
Posix Threads Rebold Programming 4 03-14-2012 10:10 AM
POSIX Threads embesil Programming 4 03-07-2009 02:03 PM
Execution threads vs normal threads jonty_11 Linux - General 2 03-26-2008 11:37 AM
POSIX Threads mannahazarika Programming 4 07-17-2006 12:00 AM
About POSIX threads Ephracis Programming 1 12-03-2004 07:33 AM


All times are GMT -5. The time now is 02:31 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