I have a bash script with doing lot of things called script.sh:#!/bin/bash#It#Is#Doing#ThingsIs there a way that I be able to get the proccess of script and then kill it after 5 minutes?Like:#!/bin/bash#Now here give pid of script.sh then kill it after 5 minutes#It#Is#Doing#ThingsupdateImagin I have this script:#!/bin/bashwhile :do      echo line printeddoneIf we use these answers it doesn't show the output...I want out put be printed and after 5 minutes cntrl + c signal kill the process of bash...Is this good idea?PID=$$kill -SIGINT $PIDWhere should be put?
Getting pid of bash script from itself
bash;process;kill;signals
If you always want the script to timeout after 5 minutes, you can simply use a block in a background process like this.  If you use Ctrl+C while it's running, the background process will also terminate:#!/bin/bash{    sleep 5m    kill $$} &while truedo    date    sleep 1done