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 6628409
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T22:07:39+00:00 2026-05-25T22:07:39+00:00

I am using top to see the thread wise cpu usage using top -H

  • 0

I am using top to see the thread wise cpu usage using

  top -H -p `pgrep app.out`

It is showing some pid for each thread like

4015
4016

I had attached gdb to the application using gdb attach command.
Now I want to switch to thread 4015 which is showing inside top o/p.

How can I do that ?

If I fire thread 4015 it is showing no thread . as I need to give thread id in gdb.

So how can I map top thread id to gdb thread id ?

  • 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-25T22:07:40+00:00Added an answer on May 25, 2026 at 10:07 pm

    You should be able to match the LWP displayed in GDB with the top information:

    according to my quick tests with Firefox, you can see that in your top -H -p:

    PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND
    6492 kevin     20   0 1242m 386m  31m S  0.3  4.9   0:09.00 firefox
    6470 kevin     20   0 1242m 386m  31m S  5.7  4.9   5:04.89 firefox
    

    and that in GDB info threads:

     22   Thread 0x7fe3d2393700 (LWP 6492) "firefox" pthread_cond_timedwait...
    ...
    * 1   Thread 0x7fe3dd868740 (LWP 6470) "firefox" __GI___poll ()...
    

    EDIT: just for you in exclusivity, here is a brand new commands for gdb: lwp_to_id <lwp>:

    import gdb
    class lwp_to_id (gdb.Command):
        def __init__(self):
            gdb.Command.__init__(self, "lwp_to_id", gdb.COMMAND_OBSCURE)
    
        def invoke(self, args, from_tty):
            lwp = int(args)
            for thr in gdb.selected_inferior().threads():
                if thr.ptid[1] == lwp:
                    print "LWP %s maps to thread #%d" % (lwp, thr.num)
                    return
            else:
                print "LWP %s doesn't match any threads in the current inferior." % lwp
    lwp_to_id()
    

    (working at least on the trunk version of GDB, not sure about the official releases !

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

Sidebar

Related Questions

Using top it's easy to identify processes that are hogging memory and cpu, but
So I'm building an App using the Entity Framework on top of SQL Compact
I see another thread somewhat like my question at: ASP.NET GridView Column - formatting
I often see sites using iframes containing an external site, and a top frame
I am trying to understand my embedded linux memory usage. By using the top
I have an app using Mongoid on top of MongoDB and an update is
I'm using Google Font API to display my website logo. (See top of stolencamerafinder.com
If I use top I can see what CPU is busy and what process
See this Link how to get last 10 rows using any aggregate function like
I am using this sliding top panel using mootools (for orientation, the code is

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.