![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| tracing processes in shell | ukndoit | Shell Programming and Scripting | 1 | 03-04-2009 09:19 AM |
| Shell script creating too many processes. | Miller_K | Shell Programming and Scripting | 3 | 05-22-2007 11:42 AM |
| need help: shell script to restart apache when no. of processes keeps growing | _joshua_ | Shell Programming and Scripting | 14 | 03-07-2007 08:06 AM |
| Howto spawn multiple child processes and wait? | siegfried | High Level Programming | 4 | 10-17-2005 01:21 AM |
| KORN Shell - Spawn new shell with commands | frustrated1 | Shell Programming and Scripting | 2 | 04-20-2005 02:23 PM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread |
Rating:
|
Display Modes |
|
|
|
||||
|
shell script for getting pid of spawn processes from shell
Hi,
I am new this forum. I request you peoples help in understanding and finding some solution to my problem. Here it goes: I need to perform this set of actions by writing a shell script. I need to read a config file for the bunch of processes to execute. I need to fecth the pid of the executed process everytime i spawn it and put it to the background processing and continue to spawn other process read from config file. Finally after spawing all process and put them for execution in background I need to wait for 10 minutes and then kill them all based on their pid's gracefully. and restart the same process. can you please let me know how to do this? I will be very thankful if you can help me on this. Example config file: =================== PARAM1_MIN=20 PARAM1_MAX=40 PARAM2_MIN=20 PARAM2_MAX=30 PARAM3_MIN=1 PARAM3_MIN=100 .... ... ... CMD="lbench -a"" ( here i need to substitute all paremeters average of min and max ) And I need to spawn a process of CMD in background and get its pid for future to kill it gracefully I will have some n number of such commands to be spawn. example:- CMD1="lbench -a (PARAM1_MIN+PARAM1_MAX)/2 -z (PARAM2_MIN+PARAM2_MAX)/2 -t (PARAM3_MIN+PARAM3_MAX)/2" I need to run such CMD's in background gettheir PID's and kill them gracefully after sleeping for 10 minutes. please help me. |
|
||||
|
Thanks TonyFullerMalv for your reply.
Yes using $$ I am able to get the pid of the current running process. Inside the script I have set of processes to be executed. When I used '$!' to get the pid of the processes. I dont see any value in that. could you please let me know how to collect the pid's of the executed commands or processes into a array. so dat using the index I can traverse through the pid list Thanks for your reply |
|
|||||
|
$! can be interpreted as run previous command again, depending on the shell, so is not PID related.
If I was killing off all the child processes I would do something like: Code:
for PROC in `ps -ef | grep " $$ " | grep -v $0 | grep -v grep | awk '{ print $2 }'`; do
if [ -n "${PROC}" -a ${PROC} -ne 1 ]; then
kill $PROC
fi
done
|
|
||||
|
Quote:
|
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|