What's my JVM bitness?

/apps/wls/bea10/jdk160_05/bin/java -d64 -version
execve(): No such file or directory
Error trying to exec /apps/wls/bea10/jdk160_05/bin/sparcv9/java.
Check if file exists and permissions are set correctly.
Failed to start a 64-bit JVM process from a 32-bit JVM.
Verify all necessary J2SE components have been installed.
(Solaris SPARC 64-bit components must be installed after 32-bit components.)

/apps/wls/bea10/jdk160_05/bin/java -d32 -version
java version "1.6.0_05"
Java(TM) SE Runtime Environment (build 1.6.0_05-b13)
Java HotSpot(TM) Server VM (build 10.0-b19, mixed mode)
 
 
uname -a
SunOS mypc 5.10 Generic_144488-07 sun4v sparc SUNW,SPARC-Enterprise-T5220

How can script to check if my JVM is 32 bit or 64 bit?

Note: I need to check this from a remote JVM or unix script as I cant deploy my code on a running JVM.

Regards,
Mohtashim

Just for try, rename

/apps/wls/bea10/jdk160_05/bin/sparcv9

to

/apps/wls/bea10/jdk160_05/bin/amd64

maybe it will fix your issue.

I dont need a fix for the above. I need to check if my running PID (JVM) is 32 bit or 64 bit from a unix script.

You may try something like this (untested):

pgrep -fl java |
  while read pid exe rest; do
    file "$exe" | 
      fgrep 64-bit &&
        printf '%s is 64-bit\n' "$exe" ||
          printf '%s is 32-bit\n' "$exe" 
done

For a specific pid use:

exe=$( ps -p<pid> -oargs= )
file "${exe%% *}" | 
  fgrep 64-bit && 
    echo 64-bit || 
      echo 32-bit

Hey that works !!

the output looks like

/apps/java/bin/rmiregistry is 32-bit
/apps/wls/bea10/jdk160_05/jre/bin/java is 32-bit
/apps/wls/bea10/jdk160_05/jre/bin/java is 32-bit
/apps/wls/bea10/jdk160_05/jre/bin/java is 32-bit

1) However, can you help me tweak your script to print respective PID next to each java.

2) How can I get the java version for a particular PID which I wish to pass as a parameter input in $1

3) Also, a small explanation of what each line does so I can play with it.

Regards,

This will print the pid:

pgrep -fl java |
  while read pid exe rest; do
    file "$exe" | 
      fgrep 64-bit &&
        printf '%d %s is 64-bit\n' $pid "$exe" ||
          printf '%d %s is 32-bit\n' $pid "$exe" 
done
exe=$(
  ps -p$1 -oargs=
  )

file "$exe" |
  fgrep 64-bit &&
    echo 64-bit ||
      echo 32-bit    

ps/pgrep gets the arguments of the process, then execute file for the first argument(...), then grep 64-bit.

Something like this:

$ ps -p2081 -oargs=
/usr/j2se/bin/java -server -XX:+BackgroundCompilation -Xmx256m -Djava.security.
$ file /usr/j2se/bin/java
/usr/j2se/bin/java:     ELF 32-bit MSB executable SPARC Version 1, dynamically linked, stripped
$ file /usr/j2se/bin/java | fgrep 64-bit && echo 64 || echo 32
32

Notice that this will return 64 even if a 64-bit java executable is running with -d32 option enabled.

1 Like

Excellect !!! i am good for now... :b:

---------- Post updated 07-01-11 at 09:29 AM ---------- Previous update was 06-30-11 at 12:14 PM ----------

Current Output

jdkbit=`file $(ps -p8423 -oargs= | awk '{print $1}') | grep 32-bit && echo 32-bit || echo 64-bit`
echo $jdkbit
/apps/wls/bea10/jdk160_05/jre/bin/java: ELF 32-bit MSB executable SPARC Version 1, dynamically linked, not stripped, no debugging information available 32-bit

But I am wanting just "32-bit" or "64-bit" to be assigned to the variable jdkbit in my script. Can you tweak this and help me?

jdkbit=$(
  file "$(
    ps -p8423 -oargs= 
    )" |
      nawk '{
        print /64-bit/ ? "64-bit" : "32-bit"
      }'      
  )
jdkbit=`file $(ps -p8423 -oargs=) | nawk '{print /64-bit/ ? "64-bit" : "32-bit"}'`

echo $jdkbit

32-bit 32-bit 32-bit

Three times it prints 32-bit ???

---------- Post updated at 02:53 PM ---------- Previous update was at 02:38 PM ----------

Hey got it ... this works

jdkbit=`file "$(ps -p8423 -oargs=)" | nawk '{print /64-bit/ ? "64-bit" : "32-bit"}'`

Thanks for all your help.