Orlo
Orlo

Reputation: 828

Ps aux: shows the same script multiple times

I have a simple script that checks for files to download. The problem is after some time I can see him multiple times running, started in different times, even though I started him only once:

ps aux | grep _db
root      2804  0.0  0.0  11288  1756 ?        S    00:26   0:06 /bin/bash /script/downloader/downloader_db.sh
root      8606  0.0  0.0  11284   872 ?        S    12:18   0:00 /bin/bash /script/downloader/downloader_db.sh
root      8649  0.0  0.0  11168   680 pts/0    S    12:18   0:00 /bin/bash /script/downloader/downloader_db.sh
root     11552  0.0  0.0  11272   860 ?        S    11:25   0:00 /bin/bash /script/downloader/downloader_db.sh
root     11562  0.0  0.0  11152   672 pts/0    S    11:25   0:00 /bin/bash /script/downloader/downloader_db.sh
root     39150  0.0  0.0  11172  1644 pts/0    S    10:51   0:01 /bin/bash /script/downloader/downloader_db.sh

I started the script with nohup from rc.local:

nohup /script/downloader/downloader_db.sh &> /dev/null &

the script:

#!/bin/bash

while true; do

    while IFS=$'\t' read -a line; do 
       ...
    sleep 2
    done < <(mysql --batch -u${user} -p${password} ${database} -e "${query}" -h ${host})
    sleep 10
done

Upvotes: 4

Views: 2142

Answers (1)

l0b0
l0b0

Reputation: 58868

Is anything in the while loop running in the background? It is conceivable that it has the same name as the parent process.

You can check whether some of the processes are subprocesses by running ps wafux and looking at the process tree.

If they are not "related" to each other, you have very likely simply run the script more than once, and the other processes are not finished yet.

Upvotes: 6

Related Questions