trap 'kill ${pid1} ${pid2}; echo "this works"' INT
Your trap command is faulty. It does not mention what signals it is trapping and has problems with the single quote characters:
Maybe try this. Note that I have twiddled with your quote characters so that the values of $pid1 and $pid2 get expanded. Any variable between single quote characters does not get expanded:
Please remember to post what Operating System and version you have and what Shell you are running (okay it is bash). Without this basic information any response is pure guesswork.
This is the info of the system that I am using:
And when I change the trap according to what you have posted, I get the following: ---------- Post updated at 03:37 PM ---------- Previous update was at 03:35 PM ----------
@Corona,
Yeah, that is exactly what is happening. I am trying to find a solution to that. Since I am fairly new to coding in linux, I am not sure how to kill the subprocesses.
Last edited by methyl; 08-27-2012 at 09:00 PM..
Reason: code tags for readability
Yeah, that is exactly what is happening. I am trying to find a solution to that. Since I am fairly new to coding in linux, I am not sure how to kill the subprocesses.
Your process doesn't get a signal unless it's sent one, so you're looking for the wrong thing.
That system is pretty old. I've got SUSE 12.x running on one of my boxes and this works for me:
First a little 'run it' script that does something (probably sleep):
If we don't see the done message, we assume it was killed. I did add a trap to run-it to verity, but the timing generated messages after the shell prompt and it was confusing.
Code to invoke the processes. the big problem, as Corona pointed out, is that the initial script doesn't wait for the asynch processes it just exits. Wait added at end to allow it to actually trap the interrupt.
The quoting is as it was on the original post; the $pid1 and $pid2 variables are expanded when the trap is executed. This allows the trap to be set before the processes are invoked; this allows for the starting several sets of processes, killing the most recently started pair when interrupted, without having to reset the trap for each. There are arguments pro and con for this I am sure, but not really the point here.
Finally, I always thought the syntax for trap is:
Specifying the signal before the command string would result in a syntax error.
Last edited by agama; 08-27-2012 at 10:52 PM..
Reason: clarification
Hello all,
I tried to parralise my treatments but after a while 'ps -ef' display all child process <defunct> (zombie)
Parent bash script to process all files (>100000) in directory:
for filename in /Data/*.txt; do
./child_pprocess.sh $filename &
done
exit(0)I understand that the... (1 Reply)
Hi guys,
I am struggling with adapting my script to increase the performance.
I created a ksh script to process a lot of files in parallel.
I would like to know how can I do in such a way that a constant number of processes is always up (until all is finished).
What I have is (not actual... (8 Replies)
Hi,
while executing shell script, in the middle of the process, if we kill the shell script( ctrl+z or ctrl+c), script will be killed and the files which using for the script will be in the folder.
How to handle those scenarios. Is there any possibilities, if user breaks the script, I need to... (3 Replies)
Hello all! I am very new to shell and Linux in general (I just started 2 days ago), I am trying to write a script that adds the size of the directories and files in a given directory and displays messages if the user puts in something wrong. I think I have covered all the possible problems except... (3 Replies)
QUESTION: How do I run processes in parallel, so that the counter (in counter.txt) would vary in value (instead of just "0" and "1")? That is, how to not sequentially run inc.sh and dec.sh?
The shared counter (a single number starting as 0) is in a file counter.txt.
counter.sh is (supposed to... (2 Replies)
Hi,
I have a generic FTP script which will be called by 28 different processes in parallel (through a GUI tool) may or may not be at the exact moment (there could be a delay of about a minute or so).
./FTP.ksh 1 (1 through 28)
This script after importing file from remote m/c... (1 Reply)
Dear gurus,
I was wondering if anybody can help.
Is it possible to distinguish whether a script was launched from a shell (interactively) or was called from another script?
I basically need to do the following: if the script was run from the command line, I want to enable logging of the... (2 Replies)
I wrote a ksh script for Helpdesk. I need to know how to disable ctrl-c,ctrl-z,ctrl-d..... so that helpdesk would not be able to get to system prompt :confused: (6 Replies)
In a korn shell script, how can I run several processes in parallel at the same time?
For example, I have 3 processes say p1, p2, p3
if I call them as
p1.ksh
p2.ksh
p3.ksh
they will run after one process finishes. But I want to run them in parallel and want to display "Process p1... (3 Replies)