Welcome to my website. I am always posting links to photo albums, art, technology and other creations. Everything that you will see on my numerous personal sites is powered by the formVistaTM Website Management Engine.


  • Subscribe to this RSS Feed
  • Use awk to Print from nth element to the End of the Line
    09/15/2015 5:03PM

    If you want to extract from the nth token to the end of the line, following is how you can do that with awk:

    Given a source file with the following:

    line1 -- 01   0011 1
    line2 -- 01   0011 2
    line3 -- 01   0011 3
    line4 -- 01   0011 4
    line5 -- 01   0011 5
    line6 -- 01   0011 6
    line7 -- 01   0011 7
    line8 -- 01   0011 8
    line9 -- 01   0011 9
    line10 -- 01   0011 10

    If you want remove the 1st, 2nd, and 3rd items from the list, you can use awk to set those fields to an empty value as follows

    awk '{$1=$2=$3=""; print $0}' test.out

    Which will result in:

       value1 00 0011 1
       value2 00 0011 2
       value3 00 0011 3
       value4 00 0011 4
       value5 00 0011 5
       value6 00 0011 6
       value7 00 0011 7
       value8 00 0011 8
       value9 00 0011 9
       value10 00 0011 10

  • JVM Option for Increasing the Default Number of Lines in the StackTrace
    09/11/2015 2:27PM

    By default (Java 1.6 or greater), the JVM will output, at most, 1024 lines of the stack trace.

    In the situation where you have some recursion problem or some infinite loop that results in a stack overflow error you will need to increase this value with a JVM option to see the origin of your crash.

    To do so, add the following option to the java command

    $ java -XX:MaxJavaStackTraceDepth=-1 -jar some.jar some.package.Class  etc, etc,

    -1 indicates no limit.  Any positive integer indicates the limit to the number of lines in the stack trace.  0 means exactly what it means and will output 0 lines.

    A great resource for java options.

  • Debugging Maven Tests by Connecting an IDE to the Maven JVM
    09/10/2015 1:50PM

    In some instances you cannot reproduce a failure or condition running a test in an IDE that manifests itself when you run it on your build server or via maven on the command line.

    In that case, it is very helpful to be able to remotely attach your IDE to the running maven process and then step through the code.

    To do so you will need to:

    Execute maven on  the command line as follows (adding any additional -D args as required by your project):

    $ mvn -Dmaven.surefire.debug test -pl module-in-question

    This will run the maven automatically pausing the JVM awaiting for a remote debugger to connect to port 5005.  If you want to have it listen on a different port you can pass it in as follows:

    $ mvn -Dmaven.surefire.debug="-Xdebug  -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8081 -Xnoagent -Djava.compiler=NONE" test -pl module-in-question

    Create a debugging run profile in either Eclipse or IntelliJ or your favorite IDE configured to connect to a JVM listening on the specified port.

    Then once you have run maven on the command line, simply execute the run configuration in your IDE and debug your application as usual.

    If need be, you can run the maven JVM on the cli such that maven does not fork the tests as follows:

    $ mvnDebug -DforkCount=0 test

  • Error attaching to process: sun.jvm.hotspot.debugger.DebuggerException: Can't attach to the process [SOLVED]
    09/09/2015 10:20AM

    If you are attempting to use jmap or another Java memory analysis tool to connect to a running JVM to generate a heap dump, even when running jmap as the same user as that of the running process, and encounter the following error:

    Attaching to process ID 2712, please wait...
    Error attaching to process: sun.jvm.hotspot.debugger.DebuggerException: Can't attach to the process

    Following is the (likely) solution to your problem.

    It is likely that the ptrace_scope setting for your system is set to a restrictive mode which will not allow another process access to the memory space of the other process.  See this link for more details.

    The fix is to update the setting in /proc/sys/kernel/yama/ptrace_scope.

    First, verify the current setting:

    $ cat /proc/sys/kernel/yama/ptrace_scope

    1, indicates a restricted setting.  To update it so that another process with the same UID can attach to that processes memory space do the following (as root)

    # echo 0 | tee /proc/sys/kernel/yama/ptrace_scope

    Now, checking that value should return 0

    $ cat /proc/sys/kernel/yama/ptrace_scope

    At this point you should now be able to do a heapdump with jmap on your process with a command similar to the following:

    $ jmap -J-d64 -heap 2712

  • Firewall for Ubuntu 14.04 LTS
    09/01/2015 4:16PM

    For whatever reason, Ubuntu 14.04 does not seem to come with a firewall.

    There are however two packages which provide, both a firewall and a handy GUI front-end for it.  UncomplicatedFireWall is the main package (ufw) and the GUI is gufw.

    To install:

    # apt-get install gufw

    This will install the front-end and the dependent packages

    To turn it on:

    # ufw enable

    The default is to block all incoming traffic.

    To update and add your own firewall rules and allow incoming connections

    # gufw

    The GUI is quite intuitive and allows advanced users the ability to create their own custom rules.

Advanced Search