Can we apply multi threading in Unix. I am using bash shell.
We have a generic script to load the data to table based on file input. For each file there is an individual table to load.
For each file found in directory I want to load the data in parallel to target table using
for file in `ls $FILE_PATH`
do
$OPT_PATH/load_script $file &
done;
$ for i in {2..5}; do
> sleep $i &
> done
[1] 50350
[2] 50351
[3] 50352
[4] 50353
Multi threading in the UNIX environment is generally a kernel level process and there is no "multi threading" for commands in a script like you provide as an example.
However, you can "multi-processing" by running tasks in the background which you are already doing with the & appended after the command and you can wait for completion of a background command with the wait command.
Suggestions: next time, be sure to tell us your OS and your shell, you will get better answers.
There is a command available from GNU called parallel which does exactly what you want. Also xargs and the & command
IF you have Linux this discusses and gives examples of each way to do what you want: