Hello everybody,<br> I have a problem in running a pthread based<br>application whose source is given below.<br>//sample.c<br>#include <stdio.h><br>#include <stdlib.h><br>#include <pthread.h
><br><br>void *thread1_function(void *);<br>void *thread2_function(void *);<br><br>int main(void)<br>{<br> pthread_t thread1,thread2;<br> char *message1 = "Thread 1";<br> char *message2 = "Thread 2";
<br> int iret1,iret2;<br> iret1 = pthread_create(&thread1,NULL,thread1_function,(void*)message1);<br> iret2 = pthread_create(&thread2,NULL,thread2_function,(void*)message2);<br><br> pthread_join(thread1,iret1);<br>
pthread_join(thread2,iret2);<br> printf("Thread 1 returns: %d\n",iret1);<br> printf("Thread 2 returns: %d\n",iret2);<br> exit(0);<br>}<br><br>void *thread1_function(void *ptr)<br>{<br> char *message;<br>
message = (char *) ptr;<br> while(1)<br> {<br> printf("%s\n",message);<br> sleep(5);<br> }<br>}<br><br>void *thread2_function(void *ptr)<br>{<br> char *message;<br> message = (char *) ptr;<br> while(1)<br> {<br>
printf("%s\n",message);<br> sleep(8);<br> }<br>}<br>//end of sample.c<br><br>I compiled using the command $powerpc-linux-uclibc-gcc -lpthread -o sample sample.c<br><br>when I run on my target board(MPC850 based custom board), I find multiple copies of the same program(I am invoking only once) is running. ps -e command show the following output.
<br><br>PID Uid VmSize Stat Command<br> 1 root 392 S init<br> 2 root SW [keventd]<br> 3 root SWN [ksoftirqd_CPU0]<br> 4 root SW [kswapd]<br> 5 root SW [bdflush]
<br> 6 root SW [kupdated]<br> 7 root SW [rpciod]<br> 36 root 1284 S /bin/snmpd -Dagentx<br> 41 root 1024 S /bin/bash<br> 42 root 372 S /sbin/syslogd -n -m 0<br>
43 root 348 S /sbin/klogd -n<br> 51 root 296 S sample<br> 52 root 296 S sample<br> 53 root 296 S sample<br> 54 root 296 S sample<br> 56 root 372 R ps<br><br>
Why is this program is running multiple copies in the memory? How to avoid this.If I compile<br>the same program in PC(x86 with glibc) It is running fine(no multiple<br>copies). So how to avoid this what is wrong with my program? Please help me.
<br><br>Regards,<br><br>Ratheesh<br>