kernelnewbies.kernelnewbies.org archive mirror
 help / color / mirror / Atom feed
* Can I get thread ID in user-mode program?
@ 2010-12-29 17:30 CP YEH
  2010-12-29 23:30 ` Dave Hylands
  2010-12-30  4:03 ` Prabhu nath
  0 siblings, 2 replies; 3+ messages in thread
From: CP YEH @ 2010-12-29 17:30 UTC (permalink / raw)
  To: kernelnewbies

Hi,

I would like to know if I can obtain thread id of calling thread. Let
me clarify what I mean by this.

First, here is task_struct from linux kernel code.

struct task_struct {
       struct list_head tasks;
       pid_t pid;
       pid_t tgid;
       struct task_struct *group_leader;  /* threadgroup leader */
       struct list_head thread_group;
};

I understand that getpid returns tgid and gettid via __NR_gettid
returns tid but according to manpage, it seems to me that it is same
as what I get from getpid().

Man page of gettid:
       gettid() returns the thread ID of the current process.  This is
equal to the
       process ID (as returned by getpid(2)), unless  the  process  is
 part  of  a
       thread  group

However, I would like to obtain pid of task_struct. Is there any way I
can get that information?
Thank you.

YEH

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Can I get thread ID in user-mode program?
  2010-12-29 17:30 Can I get thread ID in user-mode program? CP YEH
@ 2010-12-29 23:30 ` Dave Hylands
  2010-12-30  4:03 ` Prabhu nath
  1 sibling, 0 replies; 3+ messages in thread
From: Dave Hylands @ 2010-12-29 23:30 UTC (permalink / raw)
  To: kernelnewbies

Hi,

On Wed, Dec 29, 2010 at 9:30 AM, CP YEH <ntdev74@gmail.com> wrote:
> Hi,
>
> I would like to know if I can obtain thread id of calling thread. Let
> me clarify what I mean by this.
>
> First, here is task_struct from linux kernel code.
>
> struct task_struct {
> ? ? ? struct list_head tasks;
> ? ? ? pid_t pid;
> ? ? ? pid_t tgid;
> ? ? ? struct task_struct *group_leader; ?/* threadgroup leader */
> ? ? ? struct list_head thread_group;
> };
>
> I understand that getpid returns tgid and gettid via __NR_gettid
> returns tid but according to manpage, it seems to me that it is same
> as what I get from getpid().
>
> Man page of gettid:
> ? ? ? gettid() returns the thread ID of the current process. ?This is
> equal to the
> ? ? ? process ID (as returned by getpid(2)), unless ?the ?process ?is
> ?part ?of ?a
> ? ? ? thread ?group
>
> However, I would like to obtain pid of task_struct. Is there any way I
> can get that information?

>From my understanding, this sort of depends on which threading model
is being employed.

For standard distros (like ubuntu), I believe that getpid returns the
tgid, and gettid (aka syscall( 224 )) returns pid of the task struct
(which is really a thread id).

Dave Hylands

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Can I get thread ID in user-mode program?
  2010-12-29 17:30 Can I get thread ID in user-mode program? CP YEH
  2010-12-29 23:30 ` Dave Hylands
@ 2010-12-30  4:03 ` Prabhu nath
  1 sibling, 0 replies; 3+ messages in thread
From: Prabhu nath @ 2010-12-30  4:03 UTC (permalink / raw)
  To: kernelnewbies

Try this.
syscall(SYS_gettid);

This should return the value of task_struct->pid

Regards,
Prabhu



On Wed, Dec 29, 2010 at 11:00 PM, CP YEH <ntdev74@gmail.com> wrote:

> Hi,
>
> I would like to know if I can obtain thread id of calling thread. Let
> me clarify what I mean by this.
>
> First, here is task_struct from linux kernel code.
>
> struct task_struct {
>       struct list_head tasks;
>       pid_t pid;
>       pid_t tgid;
>       struct task_struct *group_leader;  /* threadgroup leader */
>       struct list_head thread_group;
> };
>
> I understand that getpid returns tgid and gettid via __NR_gettid
> returns tid but according to manpage, it seems to me that it is same
> as what I get from getpid().
>
> Man page of gettid:
>       gettid() returns the thread ID of the current process.  This is
> equal to the
>       process ID (as returned by getpid(2)), unless  the  process  is
>  part  of  a
>       thread  group
>
> However, I would like to obtain pid of task_struct. Is there any way I
> can get that information?
> Thank you.
>
> YEH
>
> _______________________________________________
> Kernelnewbies mailing list
> Kernelnewbies at kernelnewbies.org
> http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.kernelnewbies.org/pipermail/kernelnewbies/attachments/20101230/ceffcf9d/attachment.html 

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2010-12-30  4:03 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-12-29 17:30 Can I get thread ID in user-mode program? CP YEH
2010-12-29 23:30 ` Dave Hylands
2010-12-30  4:03 ` Prabhu nath

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).