From: Ratheesh <ratheeshreddy@gmail.com>
To: linuxppc-embedded@ozlabs.org
Subject: problem in running pthread application
Date: Sat, 14 Oct 2006 11:44:03 +0530 [thread overview]
Message-ID: <c94019ff0610132314h4b8bb4e2w584c340d0303cd6c@mail.gmail.com> (raw)
[-- Attachment #1: Type: text/plain, Size: 2119 bytes --]
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
[-- Attachment #2: Type: text/html, Size: 3718 bytes --]
reply other threads:[~2006-10-14 6:14 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=c94019ff0610132314h4b8bb4e2w584c340d0303cd6c@mail.gmail.com \
--to=ratheeshreddy@gmail.com \
--cc=linuxppc-embedded@ozlabs.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).