From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from py-out-1112.google.com (py-out-1112.google.com [64.233.166.176]) by ozlabs.org (Postfix) with ESMTP id 4DF2567C25 for ; Sat, 14 Oct 2006 16:14:04 +1000 (EST) Received: by py-out-1112.google.com with SMTP id t32so1458021pyc for ; Fri, 13 Oct 2006 23:14:04 -0700 (PDT) Message-ID: Date: Sat, 14 Oct 2006 11:44:03 +0530 From: Ratheesh To: linuxppc-embedded@ozlabs.org Subject: problem in running pthread application MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_Part_51343_20997481.1160806443832" List-Id: Linux on Embedded PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , ------=_Part_51343_20997481.1160806443832 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-Disposition: inline Hello everybody, I have a problem in running a pthread based application whose source is given below. //sample.c #include #include #include void *thread1_function(void *); void *thread2_function(void *); int main(void) { pthread_t thread1,thread2; char *message1 = "Thread 1"; char *message2 = "Thread 2"; int iret1,iret2; iret1 = pthread_create(&thread1,NULL,thread1_function,(void*)message1); iret2 = pthread_create(&thread2,NULL,thread2_function,(void*)message2); pthread_join(thread1,iret1); pthread_join(thread2,iret2); printf("Thread 1 returns: %d\n",iret1); printf("Thread 2 returns: %d\n",iret2); exit(0); } void *thread1_function(void *ptr) { char *message; message = (char *) ptr; while(1) { printf("%s\n",message); sleep(5); } } void *thread2_function(void *ptr) { char *message; message = (char *) ptr; while(1) { printf("%s\n",message); sleep(8); } } //end of sample.c I compiled using the command $powerpc-linux-uclibc-gcc -lpthread -o sample sample.c 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. PID Uid VmSize Stat Command 1 root 392 S init 2 root SW [keventd] 3 root SWN [ksoftirqd_CPU0] 4 root SW [kswapd] 5 root SW [bdflush] 6 root SW [kupdated] 7 root SW [rpciod] 36 root 1284 S /bin/snmpd -Dagentx 41 root 1024 S /bin/bash 42 root 372 S /sbin/syslogd -n -m 0 43 root 348 S /sbin/klogd -n 51 root 296 S sample 52 root 296 S sample 53 root 296 S sample 54 root 296 S sample 56 root 372 R ps Why is this program is running multiple copies in the memory? How to avoid this.If I compile the same program in PC(x86 with glibc) It is running fine(no multiple copies). So how to avoid this what is wrong with my program? Please help me. Regards, Ratheesh ------=_Part_51343_20997481.1160806443832 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline Hello everybody,
                         I have a problem in running a pthread based
application whose source is given below.
//sample.c
#include <stdio.h>
#include <stdlib.h>
#include <pthread.h >

void *thread1_function(void *);
void *thread2_function(void *);

int main(void)
{
 pthread_t thread1,thread2;
 char *message1 = "Thread 1";
 char *message2 = "Thread 2";
 int iret1,iret2;
 iret1 = pthread_create(&thread1,NULL,thread1_function,(void*)message1);
 iret2 = pthread_create(&thread2,NULL,thread2_function,(void*)message2);

 pthread_join(thread1,iret1);
 pthread_join(thread2,iret2);
 printf("Thread 1 returns: %d\n",iret1);
 printf("Thread 2 returns: %d\n",iret2);
 exit(0);
}

void *thread1_function(void *ptr)
{
 char *message;
 message = (char *) ptr;
 while(1)
 {
  printf("%s\n",message);
  sleep(5);
 }
}

void *thread2_function(void *ptr)
{
 char *message;
 message = (char *) ptr;
 while(1)
 {
  printf("%s\n",message);
  sleep(8);
 }
}
//end of sample.c

I compiled using the command $powerpc-linux-uclibc-gcc -lpthread -o sample sample.c

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.

PID  Uid     VmSize Stat Command
    1 root        392 S   init
    2 root            SW  [keventd]
    3 root            SWN [ksoftirqd_CPU0]
    4 root            SW  [kswapd]
    5 root            SW  [bdflush]
    6 root            SW  [kupdated]
    7 root            SW  [rpciod]
   36 root       1284 S   /bin/snmpd -Dagentx
   41 root       1024 S   /bin/bash
   42 root        372 S   /sbin/syslogd -n -m 0
   43 root        348 S   /sbin/klogd -n
   51 root        296 S   sample
   52 root        296 S   sample
   53 root        296 S   sample
   54 root        296 S   sample
   56 root        372 R   ps

Why is this program is running multiple copies in the memory? How to avoid this.If I compile
the same program in PC(x86 with glibc) It is running fine(no multiple
copies). So how to avoid this what is wrong with my program? Please help me.

Regards,

Ratheesh
------=_Part_51343_20997481.1160806443832--