15 messages in net.java.dev.jna.usersRe: [jna-users] current java thread f...
FromSent OnAttachments
QuartzOct 27, 2007 7:55 am 
Timothy WallOct 27, 2007 8:14 am 
QuartzOct 27, 2007 11:10 am 
Timothy WallOct 27, 2007 12:54 pm 
QuartzOct 28, 2007 11:03 am 
QuartzOct 28, 2007 12:44 pm 
Timothy WallOct 28, 2007 1:44 pm 
Timothy WallOct 28, 2007 1:49 pm 
Timothy WallOct 28, 2007 1:55 pm 
Timothy WallOct 28, 2007 2:30 pm 
QuartzOct 29, 2007 8:23 am 
Timothy WallOct 29, 2007 1:56 pm 
QuartzOct 29, 2007 7:39 pm 
Timothy WallOct 30, 2007 6:37 am 
QuartzNov 3, 2007 9:39 am 
Actions with this message:
Paste this link in email or IM:
Paste this link in email or IM:
Atom feed for this thread
Paste this URL into your reader:
Subject:Re: [jna-users] current java thread finding its task id yyyyy in /proc/self/task/yyyyyActions...
From:Quartz (quar@yahoo.com)
Date:Oct 27, 2007 11:10:22 am
List:net.java.dev.jna.users

Hi,

//I made an interface Pthread.java: import com.sun.jna.Library; import com.sun.jna.Native; public interface Pthread extends Library { Pthread INSTANCE = (Pthread)Native.loadLibrary("pthread", Pthread.class); int pthread_self(); }

//And them I made a simple test class: public class TaskId { public static void main(String[] args) throws Exception { System.out.println("pthread_self() returned
"+Pthread.INSTANCE.pthread_self()); } }

//Then I compiled and ran it, and got: javac -cp jna.jar *.java java -cp jna.jar:. TaskId

Exception in thread "main" java.lang.UnsatisfiedLinkError: /tmp/jna47643.tmp:
/lib/libc.so.6: version `GLIBC_2.4' not found (required by /tmp/jna47643.tmp) at java.lang.ClassLoader$NativeLibrary.load(Native Method) ...

What's going on? (forgive my lack of knowlege)

--- Timothy Wall <twal@dev.java.net> wrote:

I would guess linux uses pthreads, but you could browse the JVM source to be sure. I would imagine you might find what you're looking for in the native java.lang.Thread sources.

I'm inferring that task corresponds to thread, so if you make a pthread call to get the thread id, that might be what you're looking for.

The thread/task id might even be tucked away in a private member of a platform-specific class (this is the case with 1.6+ for AWT window handles).

On Oct 27, 2007, at 10:55 AM, Quartz wrote:

Hi,

On linux, under the jvm process of pid=xxxxx, threads usually gets listed under /proc/xxxx/tasks/*. I am trying to get the 'yyyyy' number in the proc filesystem for the current jvm thread, as in /proc/self/task/yyyyy.

As you can see, the jvm pid is not even required since there is a sym link /proc/self, but there is no such thing for the task id.

So, I don't know enough about the linux programming to drill into jni to pull this thread id. I was wondering if anyone could tell/show me the thread struct or union that describes the thread and how to pull the task id with JNA.

I hope to build an api as simple as public int LinuxThreadUtils.getProcessId(); //done: first field of content of /proc/self/stat public int LinuxThreadUtils.getCurrentThreadTaskId();//TODO

If at all possible, a bonus API would be to get the task id off the current thread, as in public int LinuxThreadUtils.getThreadTaskId(Thread t);//bonus

Thanks.