Hello,
I've to write small library using JNI. Its purpose is to provide access to CPU time of specified java threads. Class should have two public methods: one registering current Thread to be included in stats and second one to return stats as Map<Thread,long> (where long is CPU time). Whole thing should work on Solaris.
My idea to write it looks like this:
- registering method gets current thread PID (JNI) and saves Thread<->PID information somewhere
- return-stats method takes all PIDs collected by register method and for each of them retrieve CPU time (JNI), then puts Thread<->Time to Map and job is done
Question: using C getpid() function will I get current thread PID? or maybe just "java" PID ?
I know how to write most of code (both c and java), but I experienced some linkage problems while compiling c code.
Problem: while compiling this code:
#include "j_unistd.h"
#include <unistd.h>
#include <string.h>
JNIEXPORT jlong JNICALL Java_unistd_getpid
(JNIEnv *envp, jclass clazz)
{
return getpid();
}
using
gcc -shared -I. -I"$JHOME"/include -I"$JHOME"/include/solaris j_unistd.c -o libj_unistd.so
I get
Text relocation remains referenced
against symbol offset in file
getpid 0x7 /var/tmp//cchvXk7h.o
ld: fatal: relocations remain against allocatable but non-writable sections
collect2: ld returned 1 exit status
I googled for this error but I found nothing interesting. So the question is: can you help me? :)
Thank you.