Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ps aux: shows the same script multiple times

Tags:

bash

ubuntu

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
like image 291
Orlo Avatar asked Oct 19 '25 04:10

Orlo


1 Answers

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.

like image 120
l0b0 Avatar answered Oct 21 '25 21:10

l0b0



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!