pawan vinayak
pawan vinayak

Reputation: 325

how to suspended the background processes?

Below is the script named bck_grd.sh

#!/bin/bash
i=2
while [ $i -gt 0 ]
do
echo HURRAY
done

When this infinite while loop is executed in foreground, it keeps on echoing message HURRAY and this script can be suspended by ^Z (ctrl+z)

Now if the same script is ran in background (i.e. bash bck_grd.sh &)then also it keeps on echoing message HURRAY and here if i try to suspend this script using ^Z, it doesn't work. and the terminal gets tied up in displaying HURRAY message.

My question here is how can i suspend the above script while running it in background

I am using Ubuntu-11.04

Upvotes: 1

Views: 244

Answers (1)

kamituel
kamituel

Reputation: 35960

You can bring it to the foreground and then press ^Z:

./bck_grd.sh &
fg
# Now press ^Z

(note that you would type the fg command while the script is echoing the output - it's okay, as long as you remember to press enter ;))

Upvotes: 4

Related Questions