script called once, but turns two processes

0

I have here a script to test a background function.

When squeeze is launched two processes and I do not understand why.

One stops at "sleep 20", and the other runs forever.

#!/bin/bash

back(){
    n=0
    while [ 1 ]
    do      
        echo $n
        n=$(($n+1))
        sleep 5
    done
}

back &
sleep 20
exit

command "ps -a" in the call:

 PID    TTY      TIME      CMD
 8964   pts/2    00:00:00  backgroundteste
 8965   pts/2    00:00:00  backgroundteste
 8966   pts/2    00:00:00  sleep
 8982   pts/2    00:00:00  sleep

after "sleep 20":

PID    TTY      TIME      CMD
8965   pts/2    00:00:00  backgroundteste
9268   pts/2    00:00:00  sleep

Then forget about it ...

Why?

    
asked by anonymous 23.09.2016 / 10:41

1 answer

2

This command

back &

creates a background process.

Even after the original script has finished a copy of it runs in the background, because of the "&" above.

    
24.09.2016 / 04:49