Assuming that you're using bash, you're looking for the "jobs" builtin command. For instance:
Code:
#!/bin/bash
AWK="/usr/bin/awk"
DU="/usr/bin/du"
${DU} -hs /home/username/temp &
${DU} -hs /home/username/Documents &
${DU} -hs /home/username/Downloads &
job_pids=$( jobs -l | ${AWK} '{print $2}' )
for job_pid in ${job_pids} ; do
echo "job_pid = ${job_pid}"
done
exit 0
The jobs builtin will display information about each process spawned by the environment the shell script was using. Use the '-l' option to have the PID listed for each job. For more info, type
man bash and search for "SHELL BUILTIN COMMANDS" (e.g., in the man page, press the forward slash '/', type 'SHELL BUILTIN COMMANDS', and press Enter). You will need to continue scrolling down for a while, but you'll get there.
When using the '-l' option, the PID is displayed in the second column (hence the awk command).
You can then save the PIDs to a file. Your other script can read the PIDs from that file, kill the PIDs listed, and then delete the PID file.