printing thread id

1,291 views
Skip to first unread message

Pawel Por

unread,
Feb 13, 2014, 7:01:06 AM2/13/14
to nod...@googlegroups.com
Hi

How can I print thread id in node js ?
I mean thread ID (TID) not process ID (PID).

thanks for answer

Alan Hoffmeister

unread,
Feb 13, 2014, 7:04:57 AM2/13/14
to nodejs
I think that Node.js don't have threads, so no TID...
--
Att,
Alan Hoffmeister
> --
> --
> Job Board: http://jobs.nodejs.org/
> Posting guidelines:
> https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
> You received this message because you are subscribed to the Google
> Groups "nodejs" group.
> To post to this group, send email to nod...@googlegroups.com
> To unsubscribe from this group, send email to
> nodejs+un...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/nodejs?hl=en?hl=en
>
> ---
> You received this message because you are subscribed to the Google Groups
> "nodejs" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to nodejs+un...@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.

Pawel Por

unread,
Feb 13, 2014, 7:11:51 AM2/13/14
to nod...@googlegroups.com
but "ps" linux command shows that my node application consumes 2 threads.

thanks for reply

greelgorke

unread,
Feb 13, 2014, 7:43:29 AM2/13/14
to nod...@googlegroups.com
node.js does have threads under the hood, i.e. fs calles are processed by a threadpool. there is however no public api for thread id detection. only way i could think of currently is to make a system call via shell and parse it out, like 'ps -M | grep '+ process.pid

Sam Roberts

unread,
Feb 13, 2014, 4:27:04 PM2/13/14
to nod...@googlegroups.com
On Thu, Feb 13, 2014 at 4:11 AM, Pawel Por <porp...@gmail.com> wrote:
> but "ps" linux command shows that my node application consumes 2 threads.

Yeah, but your javascript always runs in the main process, which has a
tid === pid.

What exactly are you looking for? Just poking around out of curiosity?
In that case, check out the libuv headers, the in-header docs explain
or imply a lot about node.

Alexey Petrushin

unread,
Feb 13, 2014, 4:30:32 PM2/13/14
to nod...@googlegroups.com
You can have fibers instead. They are close to threads, and you can assign id to it or use fiber local storage
Reply all
Reply to author
Forward
0 new messages