LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
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, 10:21 AM   #1
YehudaSinger
Member
 
Registered: Jun 2013
Posts: 30

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, 04:14 PM   #2
Pearlseattle
Member
 
Registered: Aug 2007
Location: Zurich, Switzerland
Distribution: Gentoo
Posts: 999

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

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, 02:15 PM   #4
Pearlseattle
Member
 
Registered: Aug 2007
Location: Zurich, Switzerland
Distribution: Gentoo
Posts: 999

Rep: Reputation: 142Reputation: 142
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, 05:24 PM   #5
millgates
Member
 
Registered: Feb 2009
Location: 192.168.x.x
Distribution: Slackware
Posts: 852

Rep: Reputation: 389Reputation: 389Reputation: 389Reputation: 389
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, 04:45 AM   #6
YehudaSinger
Member
 
Registered: Jun 2013
Posts: 30

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 05:11 AM.
 
Old 04-06-2015, 07:46 AM   #7
millgates
Member
 
Registered: Feb 2009
Location: 192.168.x.x
Distribution: Slackware
Posts: 852

Rep: Reputation: 389Reputation: 389Reputation: 389Reputation: 389
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, 07:15 AM   #8
YehudaSinger
Member
 
Registered: Jun 2013
Posts: 30

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



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

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 08:33 AM.

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
Open Source Consulting | Domain Registration