devonblzx
11-24-2009, 04:26 AM
When running a shell script for example running "mysql" is there a way to execute it so it shows up as script.sh in ps/top rather mysql?
To explain further, I have two shell scripts:
script1.sh:
mysql command one
script2.sh:
mysql command two
Instead of showing two mysql commands in ps/top, how would I just show it as script1.sh and script2.sh?
devonblzx
11-24-2009, 04:30 AM
Just wanted to add this: I know top/ps will still show a script1.sh but the true cpu/memory usage will still be shown as mysql, so I would like it to be under script.sh.
mattle
11-24-2009, 11:26 AM
I doubt it. You're spawning a new process (mysql) that is actually using the system resource, not your shell script, which is basically sleeping until the process exits.
Of course, if you're interested in system resources, and the processes are hanging out in top long enough to really observe them, that probably means that you're executing a big query...most likely, mysql isn't doing much work either. It's just passing the query on to mysqld which is the process that will really be burning cycles.
Assuming you COULD keep *nix from spawning a new PID, you would still need some way of firing off a new daemon instance under your script to see the total system usage. Since you'd have to background the daemon and still fire up a client, there's pretty much no way to do this at all...
You can keep your PID if you use exec(), but your process name will still change:
#!/sw/bin/perl
print "$$\n";
system ("ps -elf | grep $$");
exit if ($ARGV[0]);
exec ("/home/mattle/exec.pl $$");
# ./exec.pl
12038
0 S root 12038 15192 0 50 20 ? 1073 ? 10:25:23 pts/2 0:00 /sw/bin/perl ./exec.pl
0 S root 12040 12039 0 50 20 ? 371 ? 10:25:23 pts/2 0:00 grep 12038
0 S root 12039 12038 0 50 20 ? 358 ? 10:25:23 pts/2 0:00 sh -c ps -elf | grep 12038
12038
0 S root 12038 15192 0 60 20 ? 1073 ? 10:25:23 pts/2 0:00 /sw/bin/perl /home/mattle/exec.pl
0 S root 12043 12042 0 60 20 ? 371 ? 10:25:23 pts/2 0:00 grep 12038
0 S root 12042 12038 0 60 20 ? 358 ? 10:25:23 pts/2 0:00 sh -c ps -elf | grep 12038
foobic
11-24-2009, 06:30 PM
cp /usr/bin/mysql ./script1.sh
./script1.sh -uuser -ppass database <file.sql:stickout:
More seriously, if this is about hiding the command parameters going into mysql, putting that info into .my.cnf can be useful.