Linux for Loop process termination method __linux

Source: Internet
Author: User

The requirement is this:

#。 /usr/bin/bash

day=0
tmpday=0
tmp2=0
#for循环执行进程, the province of a manual run for
((day=1;day<=59;day++))
Do
    if [[$day-lt]]; then
    tmpday=2018010${day}
    elif [[$day-le]]; then
    tmpday=201801${day}
    E Lif [[$day-LT 41]]; Then
    tmp2= ' expr $day -31 '
    tmpday=2018020${tmp2}
    else
    tmp2= ' expr $day -31 '  
    tmpday=201802${ TMP2}
    fi
    echo ${tmpday};
    /usr/local/hadoop/bin/hadoop jar/home/workspace/xm-bin.jar   com.xm.hadoop.Main \
-drp.input.data1=/ Input/data1/${tmpday}-data1.txt \
-drp.input.data2=/input/data2/\
-drp.output.path=/output/marathon/$ {Tmpday}
Done

The above is the content of a shell script, named 123.sh, the purpose of this script is to use Hadoop based on two input files to calculate a result, because the desire to run 59 days, so according to the original idea is to run the script 59 times, after each run to change the parameters, You later learned that you can use a for loop in the shell and then create a variable outside of the For loop, which is the background

What's the problem?
If I ran out one day to find the original Hadoop analysis file (that is, Xm-bin.jar) has a problem, need to run again, this time how to do it, the most simple and rude way is to use the following command

Hadoop Job-kill job_123456789434_1234

But if the for loop is a lot, like 100 times, you have to perform this command 100 times in this way, the head is big

Then the idea of killing the process in Linux was kill + process ID

Now the question turns into how to get the process ID of the running 123.sh script

Ps-aux

There are too many processes to find

Ps-aux|grep 123.sh or Ps-ef|grep 123.sh

The latter can be traced to the ID of the parent process, but the execution kill parent process ID is not valid

Even with the signal, that's it.

KILL-S 9 Process ID

Emperor not bear the painstaking person, finally found the answer, reference how to find the shell process number, and kill

The specific steps are:

1, in the first line of 123.sh add the following code

echo "$$" >/tmp/xm_process.pid

In this way, the ID of the script is written to the/tmp/xm_process.pid file.

2, view the process ID, and terminate the process

[Root@namenode xm]# cat/tmp/xm_process.pid
23452
[Root@namenode xm]# kill 26398

3. The 123.sh script is killed, but the Hadoop job that is already executing is still running, if there are many jobs in the job, it will run out of all the job to stop, so you need to kill the running job, so that you can completely terminate

Hadoop Job-kill job_123456789434_1234

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.