{"id":18257769,"url":"https://github.com/tomlobato/ruby-get_tid","last_synced_at":"2025-04-04T18:31:19.836Z","repository":{"id":77468492,"uuid":"125742122","full_name":"tomlobato/ruby-get_tid","owner":"tomlobato","description":"Get the Thread ID (tid/lwp/spid) in Ruby/Linux","archived":false,"fork":false,"pushed_at":"2018-03-27T17:47:11.000Z","size":11,"stargazers_count":4,"open_issues_count":0,"forks_count":2,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-20T17:04:28.158Z","etag":null,"topics":["linux","ruby","threads"],"latest_commit_sha":null,"homepage":"","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/tomlobato.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-03-18T15:57:32.000Z","updated_at":"2023-04-08T00:24:05.000Z","dependencies_parsed_at":"2023-04-30T17:46:08.470Z","dependency_job_id":null,"html_url":"https://github.com/tomlobato/ruby-get_tid","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tomlobato%2Fruby-get_tid","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tomlobato%2Fruby-get_tid/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tomlobato%2Fruby-get_tid/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tomlobato%2Fruby-get_tid/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tomlobato","download_url":"https://codeload.github.com/tomlobato/ruby-get_tid/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247229318,"owners_count":20905025,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["linux","ruby","threads"],"created_at":"2024-11-05T10:27:36.601Z","updated_at":"2025-04-04T18:31:19.830Z","avatar_url":"https://github.com/tomlobato.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"# ruby-get_tid\n\nman 2 gettid:\n\n\"gettid()  returns  the caller's thread ID (TID).  \nIn a single-threaded process, the thread ID is equal to the process ID (PID, as returned by getpid(2)).  \nIn a multithreaded process, all threads have the same PID, but each one has a unique TID.\"\n\n## Why?\n\nWhile Thread.current.object_id is great for internal thread identification, external tools (eg.: monitors) needs an OS identifier for them, for instance to get the resources stats of a specific thread.\n\n## Compile\n```bash\nruby extconf.rb\nmake\n```\n\n## Test\n\ntest.rb:\n```ruby\nrequire './thread_info'\ninclude ThreadInfo\n\nputs \"Main proccess PID: #{Process.pid}\"\nThread.new{\n    puts \"Thread TID: #{get_tid}\"\n    puts `ps axH -o pid,pgid,tid,comm,args -q #{$$}`\n}.join\n```\n\n```bash\ntom@vm1:~/ruby-get_tid# ./test.rb\nMain proccess PID: 382\nThread TID: 411\n  PID  PGID   TID COMMAND         COMMAND\n  382   382   382 ruby            ruby ./test.rb\n  382   382   410 ruby-timer-thr  ruby ./test.rb\n  382   382   411 test.rb:7       ruby ./test.rb\n```\n\n## TODO\n\n- Portability: currently working only on Linux.\n- Move get_tid method to the Process class.\n- Turn into a gem.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftomlobato%2Fruby-get_tid","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftomlobato%2Fruby-get_tid","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftomlobato%2Fruby-get_tid/lists"}