LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 11-11-2014, 11:57 AM   #1
ansonc
LQ Newbie
 
Registered: Nov 2014
Posts: 9

Rep: Reputation: Disabled
program using pthread compiled by linux-mipsel-gcc generates mutiple process


hi,
I use pthread in on a mips platfrom, which compiled with mipsel-linux-gcc.
But to my confused,when I use ps to see the pid, I got 3 process running, like this:
Quote:
1346 ans 1116 S ./ptest
1347 ans 1116 S ./ptest
1348 ans 1116 S ./ptest
the testing code is as followed:
Code:
//ptest.c
#include <stdio.h>
#include <pthread.h>
#include <unistd.h>

void* task(void* arg)
{
	pthread_detach(pthread_self());
	for(;;)
	{
	printf("do task!\n");
	sleep(1);
	}
}
int main(char argc, char** argv)
{
	pthread_t tid;
	pthread_create(&tid,NULL,task,NULL);
	for(;;)pause();
}
please anyone tell me how the extra two process come up. many thanks.

Last edited by ansonc; 11-11-2014 at 11:59 AM.
 
Old 11-11-2014, 12:36 PM   #2
rtmistler
Moderator
 
Registered: Mar 2011
Location: Sutton, MA. USA
Distribution: MINT Debian, Angstrom, SUSE, Ubuntu
Posts: 4,982
Blog Entries: 10

Rep: Reputation: 1780Reputation: 1780Reputation: 1780Reputation: 1780Reputation: 1780Reputation: 1780Reputation: 1780Reputation: 1780Reputation: 1780Reputation: 1780Reputation: 1780
Not sure of the answer, my guess would be to expect two processes, one for the main and one for the thread; however in MY particular case, I see one process. x86 32-bit machine, nothing special.

And what I did to see some more information is I added some debug prints:
Code:
        pthread_detach(pthread_self());
        printf("thread PID: %d\n", getpid());
	for(;;)
Code:
        pthread_t tid;
        printf("main PID: %d\n", getpid());
	int retval = pthread_create(&tid,NULL,task,NULL);
The result was my thread PID and main PID were the same. Perhaps you should add similar debug to determine what PID values are created and understood from within each part of that. My first question actually was to be:
Quote:
What are the parents for each of those? Was it actually 1116?
I didn't think it likely that 1116 was the parent because it's much lower than the other PIDs, except that maybe 1116 is the PID of the shell/terminal which you're running from. Still, it would seem that the parent of the second and third thread should be the original main process PID.

The only other thought is that I once heard of supervisory threads which were a thread created to look after other threads, leading to exactly what you have here. The main PID, a supervisory thread PID, and then the thread intentionally created PID.

Other final thought is that MIPS is a pipeline processor, not that there aren't other levels of sophisitication on other processors, but MIPS has always been funny like that. Unsure if that has something to do with this.

Last edited by rtmistler; 11-11-2014 at 12:39 PM.
 
Old 11-11-2014, 06:24 PM   #3
jpollard
Senior Member
 
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,683

Rep: Reputation: 1259Reputation: 1259Reputation: 1259Reputation: 1259Reputation: 1259Reputation: 1259Reputation: 1259Reputation: 1259Reputation: 1259
A "thread" on linux is a process - but a special process that shares memory/code.

If you use "ps" it will depend on what options/defaults are for what gets displayed.

You can use "top", which has options to show threads as an aggregate process rather than multiple processes.
 
Old 11-13-2014, 07:15 PM   #4
ansonc
LQ Newbie
 
Registered: Nov 2014
Posts: 9

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by rtmistler View Post
Not sure of the answer, my guess would be to expect two processes, one for the main and one for the thread; however in MY particular case, I see one process. x86 32-bit machine, nothing special.

And what I did to see some more information is I added some debug prints:
Code:
        pthread_detach(pthread_self());
        printf("thread PID: %d\n", getpid());
	for(;;)
Code:
        pthread_t tid;
        printf("main PID: %d\n", getpid());
	int retval = pthread_create(&tid,NULL,task,NULL);
The result was my thread PID and main PID were the same. Perhaps you should add similar debug to determine what PID values are created and understood from within each part of that. My first question actually was to be:I didn't think it likely that 1116 was the parent because it's much lower than the other PIDs, except that maybe 1116 is the PID of the shell/terminal which you're running from. Still, it would seem that the parent of the second and third thread should be the original main process PID.

The only other thought is that I once heard of supervisory threads which were a thread created to look after other threads, leading to exactly what you have here. The main PID, a supervisory thread PID, and then the thread intentionally created PID.

Other final thought is that MIPS is a pipeline processor, not that there aren't other levels of sophisitication on other processors, but MIPS has always been funny like that. Unsure if that has something to do with this.
hi,rtmistler
yes, I use getpid() for debug. the first column is of the ps the pid and check that is the same with getpid() I print out.
I assume that it has something to do with the libpthread on MIPS.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Cygwin gcc compiled code generates a stackdump - How to analyze with Gdb madsovenielsen Programming 3 04-13-2011 04:18 AM
Find process which generates TCP packets darkxer0x Linux - Security 9 12-19-2010 11:16 AM
Errors in Allegro in a C++ program, compiled with gcc, in a Linux console AlegroGuy Programming 9 11-17-2010 07:17 PM
mipsel-linux gcc khairilthegreat Linux - Networking 0 01-17-2007 08:21 AM
executing program compiled gcc purusingh Programming 1 08-25-2003 01:15 PM


All times are GMT -5. The time now is 01:11 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration