Re: Can I get thread ID in user-mode program?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxx> 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@xxxxxxxxxxxxxxxxx
http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies

_______________________________________________
Kernelnewbies mailing list
Kernelnewbies@xxxxxxxxxxxxxxxxx
http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies

[Index of Archives]     [Newbies FAQ]     [Linux Kernel Mentors]     [Linux Kernel Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]
  Powered by Linux