#!/bin/bash
# Copyright (c) 2014 Cloudera, Inc. All rights reserved.
#
# Runs jstack against a process, directing the output to a file.
#
# arg1: pid
# arg2: output filename

cloudera_config=`dirname $0`
cloudera_config=`cd "$cloudera_config/../common"; pwd`
. ${cloudera_config}/cloudera-config.sh

locate_java_home

set -e

if [ -e $JAVA_HOME/bin/jstack ]; then
  $JAVA_HOME/bin/jstack "$1" 2>&1 > "$2"
  exit 0
fi

echo "Missing $JAVA_HOME/bin/jstack" 1>&2
exit 1
