- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- How does a thread get its own thread id?
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Discussions
Forums
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-14-2002 12:00 PM
тАО01-14-2002 12:00 PM
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-14-2002 12:31 PM
тАО01-14-2002 12:31 PM
Re: How does a thread get its own thread id?
live free or die
harry
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-14-2002 01:46 PM
тАО01-14-2002 01:46 PM
Solution#include
#include
#include
#include
main(argc,argv)
int argc;
char *argv[];
{
int64_t mylwpid;
pid_t mypid;
int thread,ret;
struct lwp_status tbuf;
mypid = getpid();
thread = 0;
if(ret = pstat_getlwp(&tbuf,sizeof(struct lwp_status),1,thread,mypid) < 0) {
perror("pstat_getlwp");
sleep(20);
exit(-1);
}
printf("my pid is %d, lwpid is %lld\n",mypid,tbuf.lwp_lwpid);
sleep(20);
}
> cc getlwpid.c
> a.out
my pid is 25486, lwpid is 469195
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-15-2002 07:41 AM
тАО01-15-2002 07:41 AM
Re: How does a thread get its own thread id?
I was able to get the thread id returned by GlancePlus by using the pstat_getlwp() function. To get the thread id for each thread, first I used pthread_self() to get the thread number, then in the arguments to pstat_getlwp I set elemcount = 1 and index = pthread_self() - 1. I had to subtract 1 because pthread_self starts at 1 but lwpid apparently starts with index base 0.
Thanks again!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-31-2002 12:49 PM
тАО07-31-2002 12:49 PM
Re: How does a thread get its own thread id?
In my application, I can call pstat_getlwp passing an index equal to (pthread_self()-1) only until a thread exits. Once a thread exits, all further calls to pstat_getlwp fail with errno=3 (No such process). I think this is because pthread_self() returns a number that is monotonically increasing for the given process, whereas the index required by pstat_getlwp is bounded by the number of active threads (light-weight processes) in the process.
So, my question becomes: How do I determine the proper index of the current thread (lwp)?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-12-2002 04:01 PM
тАО08-12-2002 04:01 PM
Re: How does a thread get its own thread id?
My application runs on HP-UX 11.00 and up, 32-bit and 64-bit executables.