2015-05-27

C: fun on the 404 page of stackoverflow

I found this fun on the SO's 404 page:
Of course, it is a pretty lightly obfuscated C code printing out "404".

This is what will get effectively compiled and executed (you can verify with gcc -E -P):
main(){putchar(4+putchar(putchar(52)-4));return 0;};exit();
As putc returns the character it printed out, the magic is easy:
  1. Print the character dec 52  (which is the digit four)
  2. Print the character dec 52-4 = dec 48 (which is the digit zero)
  3. Print the character dec 48+4 = dec 52 again

2015-05-12

Shell: Get threaddump directly from the java process

Inspecting the Java source, I found a pretty easy way to skip java in the process of extracting info from another java process :-)

PID=`pgrep java`
SCKT=/tmp/.java_pid$PID
SGNL=/tmp/.attach_pid$PID
CMD='1\0threaddump\0\0\0\0'

if [ ! -r $SCKT ]; then
 touch $SGNL || exit 2
 kill -s SIGQUIT $PID
 sleep 5
 rm $SGNL
 if [ ! -r $SCKT ]; then
  echo Cannot read $SCKT ... either you are not the correct user for this, or the java process does not 'see' our attach request.
  exit 1
 fi
 echo Done
fi

echo -ne "$CMD" | nc -U "$SCKT"

Possible options and variations I know about:
  • 1\0threaddump\0-l\0\0\0 small L for the jstack -L option
  • 1\0inspectheap\0\0\0\0
  • 1\0inspectheap\0-live\0\0\0
For others see the attachListener.cpp (JDK7, JDK8)

    2015-05-05

    Oracle: ANSI JOIN recommended since 9.2?

    Look at this gem I found in the Oracle 9i (!!!) [released in 2001] documentation.

    http://docs.oracle.com/cd/B10501_01/server.920/a96540/queries7.htm#2054065
    Oracle Corporation recommends that you use the FROM clause OUTER JOIN syntax rather than the Oracle join operator. Outer join queries that use the Oracle join operator (+) are subject to the following rules and restrictions(...)
    Also, http://docs.oracle.com/cd/B10501_01/server.920/a96540/statements_103a.htm#2091953
    Oracle Corporation strongly recommends that you use the more flexible Oracle9i FROM clause join syntax shown in the former example.
    What is this "FROM clause join syntax"?

    It is The ANSI JOIN syntax.

    Lol.