LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 11-26-2004, 09:05 AM   #1
msriram_linux
LQ Newbie
 
Registered: Nov 2004
Posts: 19

Rep: Reputation: 0
Process and thread PIDs


Hi!
I was referring to Advanced Linux Programming downloaded from net(Pearson Education).
While distinguishing between threads-implementation on GNU/Linux systems from other UNIX-like systems it says every invocation of pthread_create creates a new process to run it
and the following example to prove it:
-------------------------------------------------------------------
#include<pthread.h>
#include<stdio.h>
#include<unistd.h>

void* thread-function(void* arg)
{
fprintf(stderr,"\n---child thread pid is %d -----\n",getpid());
while(1);
return(NULL);
}

int main()
{
pthread_t thread;
pthread_create(&thread,NULL,&fun,NULL);
fprintf(stderr,"\n---Main thread pid is %d -----\n",getpid());
while(1);
return(0);
}
------------------------------------------------
The output is expected ot be the main and the child with different pid.
However while I run this program I get the same pid for the child and main.
I am using RED HAT-9,
The Kernel version is 2.4.20-8
Can someone point what is it.
Regards,
 
Old 11-26-2004, 11:21 AM   #2
indian
Member
 
Registered: Aug 2004
Posts: 137

Rep: Reputation: 15
Hi Sriram , Do a thing man...In Main() put

wait(2);

before

fprintf(stderr,"\n---Main thread pid is %d -----\n",getpid());

and after

pthread_create(&thread,NULL,&fun,NULL);

And than see what output it is giving!!!

Regards,
 
Old 11-26-2004, 11:22 AM   #3
indian
Member
 
Registered: Aug 2004
Posts: 137

Rep: Reputation: 15
and remove while loops........
 
Old 11-27-2004, 01:16 AM   #4
msriram_linux
LQ Newbie
 
Registered: Nov 2004
Posts: 19

Original Poster
Rep: Reputation: 0
Dear Indian
I tried that but it didn't work...there is no change in output.
Is there any material on this particular topic...
Regards,
 
Old 11-27-2004, 11:43 AM   #5
btmiller
Senior Member
 
Registered: May 2004
Location: In the DC 'burbs
Distribution: Arch, Scientific Linux, Debian, Ubuntu
Posts: 4,290

Rep: Reputation: 378Reputation: 378Reputation: 378Reputation: 378
This link ought to help you resolve your difficulty. Basically, recent versions of Linux actually return the thread group ID, not the thread ID, when you call getpid(2). So your correct that Linux has a 1-1 provesses-threads implementationm -- it's just hidden.
 
  


Reply



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
what happens if i create a thread and then fork the process? Thinking Programming 7 10-31-2005 02:22 PM
what advantage do kernel thread has over process? keiwu Linux - Software 1 03-04-2005 07:18 PM
what advantage do kernel thread has over process? keiwu Linux - Newbie 3 03-04-2005 04:04 PM
Multi-Thread/Process Pipes JanusPaul Programming 2 02-27-2005 02:52 PM
Controlling process and thread security synna Programming 4 01-27-2004 06:28 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 12:49 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
Open Source Consulting | Domain Registration