How to send control+c from a bash script?

前端 未结 5 1677
孤街浪徒
孤街浪徒 2020-12-02 11:05

I\'m starting a number of screens in a bash script, then running django\'s runserver command in each of them. I\'d like to be able to programmatically stop them

5条回答
  •  既然无缘
    2020-12-02 11:36

        pgrep -f process_name > any_file_name
        sed -i 's/^/kill /' any_file_name
        chmod 777 any_file_name
        ./any_file_name
    

    for example 'pgrep -f firefox' will grep the PID of running 'firefox' and will save this PID to a file called 'any_file_name'. 'sed' command will add the 'kill' in the beginning of the PID number in 'any_file_name' file. Third line will make 'any_file_name' file executable. Now forth line will kill the PID available in the file 'any_file_name'. Writing the above four lines in a file and executing that file can do the control-C. Working absolutely fine for me.

提交回复
热议问题