LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 08-15-2005, 11:03 PM   #1
ninelion
LQ Newbie
 
Registered: Oct 2004
Posts: 3

Rep: Reputation: 0
How do I get the LWP pid of linux threads?


I remember getpid() return different pid in seperated threads in redhat 7, but it return the same pid in redhat 9 and later. I think the latter should follows the POSIX thread specification, but I want the the old form reult now.
 
Old 08-16-2005, 12:56 AM   #2
Matir
LQ Guru
 
Registered: Nov 2004
Location: San Jose, CA
Distribution: Debian, Arch
Posts: 8,507

Rep: Reputation: 128Reputation: 128
getpid() returns the process pid. POSIX-ly correct, all threads of a process execute under that process id, hence getpid() returning the same value. You wouldn't want it to make up values, or use the values of another process, would you?
 
Old 08-16-2005, 01:36 AM   #3
ninelion
LQ Newbie
 
Registered: Oct 2004
Posts: 3

Original Poster
Rep: Reputation: 0
I want to know which thread is the busiest one. but on the redhat9 the 'top' or 'ps' could only tell me the pid of differnce thread. and in the code I can got thread id only. I can't figure the mapping among them.

the follow is the output of 'ps -C npserver -m -o pid,tid,pcpu,tname,stat,psr,cmd'
Code:
  PID TID %CPU TTY    STAT PSR CMD
15489 -  0.1 ?        S      - /usr/local/bin/npserver
15490 -  0.0 ?        S      - /usr/local/bin/npserver
15492 -  0.0 ?        S      - /usr/local/bin/npserver
15493 -  0.0 ?        S      - /usr/local/bin/npserver
15494 -  0.0 ?        S      - /usr/local/bin/npserver
15495 -  0.0 ?        S      - /usr/local/bin/npserver
15496 -  0.0 ?        S      - /usr/local/bin/npserver
15497 -  0.0 ?        S      - /usr/local/bin/npserver
15498 -  0.0 ?        S      - /usr/local/bin/npserver
on Redhat AS4, I got the following output
Code:
  PID   TID %CPU TTY      STAT PSR CMD
14470     -  0.0 ?        -      - /usr/local/bin/npserver
    - 14470  0.0 -        Sl     0 -
    - 14471  0.0 -        Sl     0 -
    - 14472  0.0 -        Sl     0 -
    - 14473  0.0 -        Sl     0 -
    - 14474  0.0 -        Sl     0 -
    - 14475  0.1 -        Sl     0 -
    - 14476  0.0 -        Sl     0 -
    - 14477  0.0 -        Sl     0 -
    - 14478  0.0 -        Sl     0 -
    - 14480  0.0 -        Sl     0 -

Last edited by ninelion; 08-16-2005 at 04:11 AM.
 
Old 08-16-2005, 12:51 PM   #4
bbeers
Member
 
Registered: Jul 2002
Location: Florida
Distribution: Centos, Slackware
Posts: 260

Rep: Reputation: 30
How about putting something like this at the beginning of each thread?

printf("%s: Starting this thread[pid = %d] ...\n",
__FUNCTION__, getpid());

-bbeers
 
Old 08-16-2005, 08:32 PM   #5
ninelion
LQ Newbie
 
Registered: Oct 2004
Posts: 3

Original Poster
Rep: Reputation: 0
thanksŁ¬but the getpid() got the same value in all threads.
I have found it, the gettid() is just what I wantŁ¬but in redhat 9, it could only be referenced by syscall() form.
 
  


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
Java threads listed using kill -3 does not contain all threads found using ps -auxww coneheed Programming 2 11-14-2005 08:57 AM
Linux Software to read .lwp (Lotus Files) rvijay Linux - Software 0 02-09-2005 07:47 AM
/var/run/[XXX].pid - Tcl pid code liguorir Linux - Software 1 05-20-2004 10:32 PM
ERROR: Couldn't write pid to pid file lawrencegoodman Linux - Newbie 2 02-13-2004 08:05 PM
using LWP linuxRules Programming 0 06-27-2002 01:20 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

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