From: gprabhunath@gmail.com (Prabhu nath)
To: kernelnewbies@lists.kernelnewbies.org
Subject: Can I get thread ID in user-mode program?
Date: Thu, 30 Dec 2010 09:33:37 +0530 [thread overview]
Message-ID: <AANLkTime-NvQoeBaP1wuy-0-3Ta5Nqhr0M5xsVtemzQH@mail.gmail.com> (raw)
In-Reply-To: <AANLkTinPkaX_4fn-CeQccdZBgyHa_hBC-G9zqTkChnhn@mail.gmail.com>
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
prev parent reply other threads:[~2010-12-30 4:03 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
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 message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=AANLkTime-NvQoeBaP1wuy-0-3Ta5Nqhr0M5xsVtemzQH@mail.gmail.com \
--to=gprabhunath@gmail.com \
--cc=kernelnewbies@lists.kernelnewbies.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).