[LCP]Help in Threads

Andrew Weaver Andrew.Weaver at tecnomen.fi
Thu Nov 21 15:38:01 UTC 2002


Well, these are not "threads". Have you explored semaphores? 

On Thursday, November 21, 2002 6:14 AM, Mohd Saifullah
[SMTP:saif at lantana.tenet.res.in] wrote:
> 
> Hello,
> 
> I am appending the code that i am trying out (this time with processes).
> 
> main()
> {
>   int upid;
>   upid =  fork();
>   if(upid == 0)
>     {
>       system("snmpget localhost public .1.3.6.1.2.1.2.2.1.10.2 > file1");

>       usleep(1000000);
>       system("snmpget localhost public .1.3.6.1.2.1.2.2.1.10.2 >> file1");
>       exit(0);
>     }
>   else
>     {
>     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?
> 
> Regards,
> Saif 
> 
> 
>  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.
> > 
> > 
> 
> _______________________________________________
> This is the Linux C Programming List
> :  http://lists.linux.org.au/listinfo/linuxcprogramming List



More information about the linuxCprogramming mailing list