so i've been using this a lot in a lot of my scripts:
It seems to work as ive seen it dramatically reduce run time of my scripts.
however, i'm wondering if there's another way to do the above? a better way, maybe? one that' is of course portable and will be faster??
i'm using /bin/sh
You're using an unneeded subshell and running several background jobs that do not need to be in the background. Your script could more simply (and slightly more efficiently) be written as:
or if you don't have any other background jobs and aren't going to check the exit status of each individual wait command to verify that all three jobs completed successfully:
This User Gave Thanks to Don Cragun For This Post:
As the title of this thread suggests you confuse multithreading and multitasking.
The difference between a thread and a task is that a task is a process in its own rights: complete with its own process environment, its own stack, its own text segments, data segments, and so on. A thread has nothing of that. It is just a separate succession of machine statements sharing the process environment with all the other threads which make up this certain process.
Multitasking is having several processes run at once. Multithreading means that one process has several threads (usually utilizing a CPU specifically designed to support that).
What you do here is multitasking. You start several processes (even the same executable started several times will create separate processes) and if these processes are multithreaded depends on the exectuable.
As the title of this thread suggests you confuse multithreading and multitasking.
The difference between a thread and a task is that a task is a process in its own rights: complete with its own process environment, its own stack, its own text segments, data segments, and so on. A thread has nothing of that. It is just a separate succession of machine statements sharing the process environment with all the other threads which make up this certain process.
Multitasking is having several processes run at once. Multithreading means that one process has several threads (usually utilizing a CPU specifically designed to support that).
What you do here is multitasking. You start several processes (even the same executable started several times will create separate processes) and if these processes are multithreaded depends on the exectuable.
I hope this helps.
bakunin
thank you for this. any additional ideas on how to make what i have in my original post more efficient?
i read somewhere that i can "pipe" the functions, but i haven't seen an example on how to do this.
Let me see if I understand this. You have three scripts that do something or nothing and they do whatever they do faster if you run them in parallel than if you run them serially. And, you want us to tell you how to convert those three scripts into functions that can be piped together to do something or nothing faster. If these three scripts run faster in parallel instead of serially, why would connecting them with pipes make them run faster? Connecting three scripts with pipes implies that the output of one of the scripts is input to one of the other scripts and the output of that script is input to the third script; but if you are running them in parallel, that can't be true.
Don't you think we might have a better chance of helping you figure out if there is a way to optimize what your three scripts are doing if we knew something about what those three scripts are doing?
These 3 Users Gave Thanks to Don Cragun For This Post:
any additional ideas on how to make what i have in my original post more efficient?
i read somewhere that i can "pipe" the functions, but i haven't seen an example on how to do this.
I do not know what you mean by "pipe functions".
What i can suggest, though, is to make the parallelisation scheme more flexible, but if this is possible at all depends on the exact problem you are working on and how much parallelisation it allows for.
Suppose you have some "stream" of values you want to work on coming from somewhere, like in the following loop "VAL" is fed consecutive values:
To work on several values of VAL at the same time we first need to define a fanout value: it only makes sense to have so many parallel instances of some_command running at the same time. How many exactly depends on your system, the nature of some_command, the nature of your input data (the values of VAL) and perhaps a few other things but there will be *some* value whic is optimal. Let us call this value FANOUT. Here is what we are going to do, first in pseudocode:
here is a sketch for a solution in shell (ksh actually):
It should be feasible to pack this into a generic function and call that with the command to execute as parameters. Something like this (not tested):
Save for that i share Don Craguns astute observations: if you show us "something like" your problem you are likely to get "something like" an answer, most probably producing only "something like" the desired result instead of the real thing.
Hi,
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
... (3 Replies)
Hi All
I have been asked to write scripts within our monitoring tool for a vast requirement set.
One of the requirements is below:
• Lowest, Highest & Average response times of the Documentum process threads serving client requests
Essentially they want a view where we can see the... (4 Replies)
Hello everybody ,
I launched cron to execute a task every hour but the job takes more than hour that's why I'm getting more than 1000 cron processes running at the same time !!!
My question is how to tell cron not to execute unless the job terminated in order to have only one process running .... (14 Replies)
Hi, I am trying to get my head round Multi Threading and I have a few queries to try and clear up my confusion
Q1. Is multi threading a hardware / chip level concept, an OS level or an application level concept ? I am trying to work out where SMT architecture fits in.
Q2. What's the multi... (3 Replies)
In this piece i implemented the gossip method. The first thread is invoked from inside the (msg is first sent from node -1 to 0 from main()) and the other threads are invoked from inside of the thread function itself. I used two mutexes and a condition variable to control the synchronization. ... (4 Replies)
Hi, If we create 10 threads to invoke runQuery method at same time, Will queryProcessor will be overriden sometime or 10 different copies will be created?
We are not using any sunchronzation mechnism in runQuery(). so there is not gurantee on QueryProcessor class variables right OR each 10... (1 Reply)
I am not sure if multi threading is the correct term, but here is what I am trying to do. I have a while loop that displays the number 1, pauses, displays the number 2, pauses , displays the number 3 ad infinitum. It just keeps counting.
While the screen displays the sequence of numbers counting... (4 Replies)
Hi All,
Here's my question
I have a 385 MB file containing 5,000,000 records.
I need to read from the file and load into a table.
Initially i thought of doing it in a single thread (execution of a single program) but when calculated accounted 16 hours of time on a standard benchmark.
Hence... (5 Replies)
Hi,
I have written a code which will run a set of process using
fork.
I want to know from You how can i start another job when one of my job in my loop is completed
My code is
#include<stdio.h>
#include<ctype.h>
main() {
int pid,cid;
ChildProcess();
... (1 Reply)
I've been doing some reading lately about threading (Posix threads) and I'm really curious about a couple things that I've read. I'm not sure if many people here have threading experience, but I thought it would be nice to be able to discuss some questions about it.
(For the record, I did... (1 Reply)