ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From robert lazarski <>
Subject Re: Killing Ant process through shell script when multiple Java processes are running...
Date Wed, 25 Nov 2009 10:06:52 GMT
On Wed, Nov 25, 2009 at 6:49 AM, Harry_ <> wrote:
> And one more thing I would like to ask is about how to get the list of
> processes created by a process. I want this to make sure that all the
> processes created by parent ant process are also killed once I Killed ant
> process. Any way ant can write the output of new processes created into a
> file. Then we can read them and  kill them after killing the ant process.

I use this in bash for killing the desired process and its child
processes. Some pid's might duplicate in the list that gets sent to be
killed, which is not a problem. ymmv.

function killSubs () {
    process_list=`ps -ef`
    printf "\n\n'ps' output before PID's were killed: \n$process_list"
>> $stdout_this_script
    sub_ids_all=`ps ef -o pid,ppid`
    printf "\n\nsub_ids_all: \n$sub_ids_all" >> $stdout_this_script
    sub_ids=`ps ef -o pid,ppid | grep $CURRENT_PID | awk '{ print $1 '}`
    printf "\n\nsub_ids for $CURRENT_PID: \n$sub_ids" >> $stdout_this_script
    # guarantee at least one pid is sent to be killed,
    # ideally its also able to find child id's
    sub_ids=$CURRENT_PID" "$sub_ids
    printf "\n\nsub_ids with CURRENT_PID $CURRENT_PID: \n$sub_ids" >>
    while read -ra pid_number; do
      for i in "${pid_number[@]}"; do
          child_id=`ps ef -o pid,ppid | grep $i | awk '{ print $1 '}`
          printf "\n\nfound child_id: \n$child_id , from ppid: $i " >>
          sub_ids=$child_id" "$sub_ids
    done <<< "$sub_ids"
    printf "\n\nkilling child pids: $sub_ids " >> $stdout_this_script
    kill -9 $sub_ids >> $stdout_this_script 2>&1

stdout_this_script="my_logs_`date +%F_%H_%M_%S`.log"
killSubs >> $stdout_this_script 2>&1

- R

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message