Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6954383
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T14:35:55+00:00 2026-05-27T14:35:55+00:00

Suppose we have many user processes running on Linux. Each process has many threads

  • 0

Suppose we have many user processes running on Linux. Each process has many threads running.

I can get process ID by calling getpid(), the return value of which is an integer.

I can get thread ID by calling pthread_self(), the return value of which is an opaque type called pthread_t.

Now I need to store the process ID (an int, typically 4 bytes) and the thread ID (pthread_t, need to figure out how many bytes) in shared memory so that I can later use the two pieces of ID information to identify that specific thread and to check if the thread is still running or not.

I’ve found many online sources cast pthread_t to either unsigned int or unsigned long. Since I don’t want any data loss during the casting, how should I deal with the pthread_t data so that it’s a fixed-size piece of data (as mentioned, I need to store the thread information in shared memory).

Also, how should I identify that specific thread by combination of process ID and thread ID later? How to check if the thread is still running or not?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T14:35:55+00:00Added an answer on May 27, 2026 at 2:35 pm

    If you want to store pid_t and pthread_t anywhere, you should use their respective types (i.e. “pid_t” and “pthread_t”). So if you want to store them in shared memory somewhere, do a memcpy() to get them there.

    As far as identifying specific threads by combinations of PID and TID, see Nemo’s comment.

    If you do make the assumption that they will exist, you can have your program look at /proc to find the appropriate pid’s directory, and looking in /proc/<pid>/task for the threads.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Suppose we have two models, Task and User. So a user can have many
Suppose I have a blog post entity. It has many attributes It has comments
suppose i have many html control in the page and all the control has
Suppose I have two entities: User and UserGroup . They have a one-to-many relationship
Suppose I have the classes/models Projects (has many lists) Lists I want to allow
Suppose we have classes Gallery and Image. There can be many images in one
Suppose I create collection like Collection<IMyType> coll; Then I have many implelentations of IMyTypem
suppose I have a class with many explicit (statically allocated) members and few pointers
Suppose I have: Toby Tiny Tory Tily Is there an algorithm that can easily
Suppose I have a table called Companies that has a DepartmentID column. There's also

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.