[LCP]Help in Threads
saif at lantana.tenet.res.in
Thu Nov 21 12:17:01 UTC 2002
I am appending the code that i am trying out (this time with processes).
upid = fork();
if(upid == 0)
system("snmpget localhost public .22.214.171.124.126.96.36.199.1.10.2 > file1");
system("snmpget localhost public .188.8.131.52.184.108.40.206.1.10.2 >> file1");
system("ping -i 0.01 -c 100 -s 954 -q fileserver > pingout");
My exact requirement is: the first snmpget of child process has to be
executed little after parent process starts "ping". And also the second
snmpget of child process has to run before parent process stops pingning.
Any idea, please?
On Wed, 20 Nov 2002, David wrote:
> Mohd Saifullah wrote:
> > Greetings to All!
> > I have written two threads (Linux pthreads). One thread does "ping"ing for
> > two to three secs. The other thread has to note down the interface traffic
> > count at the beginning of the pinging and also at the end of it, so this
> > thread has 2 secs sleep in between the two readings. But the problem is:
> > first thread is executed completely and then control comes to second
> > thread. But i want control to switch from first thread to second thread as
> > soon as first one starts pinging.
> > Thanks in advance,
> > Saif
> Have you thought using a condition variable? You could use it make the
> first thread signal the second and wait until the second thread completes.
> The second thread could then signal the first when it is finished.
More information about the linuxCprogramming