* same pid ? [not found] <AANLkTincdyMFR2Yb-HVvKmqoVTyTvSXweM5K_WLzFijC@mail.gmail.com> @ 2011-02-10 11:37 ` ratheesh k 2011-02-10 12:22 ` Michal Nazarewicz 0 siblings, 1 reply; 8+ messages in thread From: ratheesh k @ 2011-02-10 11:37 UTC (permalink / raw) To: linux-c-programming i created two threads with pthread library. But both threads returns same pid with getpid() function. ??? -Ratheesh ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: same pid ? 2011-02-10 11:37 ` same pid ? ratheesh k @ 2011-02-10 12:22 ` Michal Nazarewicz 2011-02-10 18:09 ` ratheesh k 0 siblings, 1 reply; 8+ messages in thread From: Michal Nazarewicz @ 2011-02-10 12:22 UTC (permalink / raw) To: linux-c-programming, ratheesh k On Thu, 10 Feb 2011 12:37:25 +0100, ratheesh k <ratheesh.ksz@gmail.com> wrote: > i created two threads with pthread library. But both threads returns > same pid with getpid() function. ??? PID is a Process ID. All threads in given process have the same PID. -- Best regards, _ _ .o. | Liege of Serenly Enlightened Majesty of o' \,=./ `o ..o | Computer Science, Michal "mina86" Nazarewicz (o o) ooo +-<email/jid: mnazarewicz@google.com>--------ooO--(_)--Ooo-- ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: same pid ? 2011-02-10 12:22 ` Michal Nazarewicz @ 2011-02-10 18:09 ` ratheesh k 2011-02-10 23:26 ` Jonathan Isom 0 siblings, 1 reply; 8+ messages in thread From: ratheesh k @ 2011-02-10 18:09 UTC (permalink / raw) To: Michal Nazarewicz; +Cc: linux-c-programming 2011/2/10 Michal Nazarewicz <mina86@mina86.com>: > On Thu, 10 Feb 2011 12:37:25 +0100, ratheesh k <ratheesh.ksz@gmail.com> > wrote: >> >> i created two threads with pthread library. But both threads returns >> same pid with getpid() function. ??? > > PID is a Process ID. All threads in given process have the same PID. > pthread uses clone system call. doen't it ? if so, please see - man clone CLONE_PID (obsolete) If CLONE_PID is set, the child process is created with the same process ID as the calling process. This is good for hacking the system, but otherwise of not much use. Since 2.3.21 this flag can be specified only by the system boot process (PID 0). It disappeared in Linux 2.5.16. > -- > Best regards, _ _ > .o. | Liege of Serenly Enlightened Majesty of o' \,=./ `o > ..o | Computer Science, Michal "mina86" Nazarewicz (o o) > ooo +-<email/jid: mnazarewicz@google.com>--------ooO--(_)--Ooo-- > -- To unsubscribe from this list: send the line "unsubscribe linux-c-programming" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: same pid ? 2011-02-10 18:09 ` ratheesh k @ 2011-02-10 23:26 ` Jonathan Isom 2011-02-11 2:18 ` ratheesh k 0 siblings, 1 reply; 8+ messages in thread From: Jonathan Isom @ 2011-02-10 23:26 UTC (permalink / raw) To: ratheesh k; +Cc: Michal Nazarewicz, linux-c-programming On Thu, Feb 10, 2011 at 12:09 PM, ratheesh k <ratheesh.ksz@gmail.com> wrote: > 2011/2/10 Michal Nazarewicz <mina86@mina86.com>: >> On Thu, 10 Feb 2011 12:37:25 +0100, ratheesh k <ratheesh.ksz@gmail.com> >> wrote: >>> >>> i created two threads with pthread library. But both threads returns >>> same pid with getpid() function. ??? >> >> PID is a Process ID. All threads in given process have the same PID. >> > > pthread uses clone system call. doen't it ? if so, please see - man clone > > > CLONE_PID (obsolete) > If CLONE_PID is set, the child process is created with the same > process ID as the calling process. This is good for hacking the > system, but otherwise of not much use. Since 2.3.21 this flag > can be specified only by the system boot process (PID 0). It > disappeared in Linux 2.5.16. > > Newer distros use Native POSIX Thread Library (NPTL). They return the same pid. > > > > > >> -- >> Best regards, _ _ >> .o. | Liege of Serenly Enlightened Majesty of o' \,=./ `o >> ..o | Computer Science, Michal "mina86" Nazarewicz (o o) >> ooo +-<email/jid: mnazarewicz@google.com>--------ooO--(_)--Ooo-- >> > -- > To unsubscribe from this list: send the line "unsubscribe linux-c-programming" in > the body of a message to majordomo@vger.kernel.org > More majordomo info at http://vger.kernel.org/majordomo-info.html > -- ASUS M4A78 PRO motherboard Athlon II X4 640 Processor 4 Gigabytes of DDR2-800 Galaxy GTX 465 Graphics adapter KWorld ATSC 110 TV Capture Card KWorld ATSC 115 TV Capture Card -- To unsubscribe from this list: send the line "unsubscribe linux-c-programming" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: same pid ? 2011-02-10 23:26 ` Jonathan Isom @ 2011-02-11 2:18 ` ratheesh k 2011-02-11 5:12 ` Steve Graegert (スティーブ) 0 siblings, 1 reply; 8+ messages in thread From: ratheesh k @ 2011-02-11 2:18 UTC (permalink / raw) To: Jonathan Isom; +Cc: Michal Nazarewicz, linux-c-programming >On Fri, Feb 11, 2011 at 4:56 AM, Jonathan Isom <jeisom@gmail.com> wrote: > Newer distros use Native POSIX Thread Library (NPTL). They return the same pid. > > if linux treats every thing as task (both thread and process ) and CLONE_PID flag is obsolete, i expected unique pid. -ratheesh On Fri, Feb 11, 2011 at 4:56 AM, Jonathan Isom <jeisom@gmail.com> wrote: > On Thu, Feb 10, 2011 at 12:09 PM, ratheesh k <ratheesh.ksz@gmail.com> wrote: >> 2011/2/10 Michal Nazarewicz <mina86@mina86.com>: >>> On Thu, 10 Feb 2011 12:37:25 +0100, ratheesh k <ratheesh.ksz@gmail.com> >>> wrote: >>>> >>>> i created two threads with pthread library. But both threads returns >>>> same pid with getpid() function. ??? >>> >>> PID is a Process ID. All threads in given process have the same PID. >>> >> >> pthread uses clone system call. doen't it ? if so, please see - man clone >> >> >> CLONE_PID (obsolete) >> If CLONE_PID is set, the child process is created with the same >> process ID as the calling process. This is good for hacking the >> system, but otherwise of not much use. Since 2.3.21 this flag >> can be specified only by the system boot process (PID 0). It >> disappeared in Linux 2.5.16. >> >> > > Newer distros use Native POSIX Thread Library (NPTL). They return the same pid. > > >> >> >> >> >> >>> -- >>> Best regards, _ _ >>> .o. | Liege of Serenly Enlightened Majesty of o' \,=./ `o >>> ..o | Computer Science, Michal "mina86" Nazarewicz (o o) >>> ooo +-<email/jid: mnazarewicz@google.com>--------ooO--(_)--Ooo-- >>> >> -- >> To unsubscribe from this list: send the line "unsubscribe linux-c-programming" in >> the body of a message to majordomo@vger.kernel.org >> More majordomo info at http://vger.kernel.org/majordomo-info.html >> > > > > -- > ASUS M4A78 PRO motherboard > Athlon II X4 640 Processor > 4 Gigabytes of DDR2-800 > Galaxy GTX 465 Graphics adapter > KWorld ATSC 110 TV Capture Card > KWorld ATSC 115 TV Capture Card > -- To unsubscribe from this list: send the line "unsubscribe linux-c-programming" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: same pid ? 2011-02-11 2:18 ` ratheesh k @ 2011-02-11 5:12 ` Steve Graegert (スティーブ) 2011-02-11 7:19 ` ratheesh k 0 siblings, 1 reply; 8+ messages in thread From: Steve Graegert (スティーブ) @ 2011-02-11 5:12 UTC (permalink / raw) To: ratheesh k; +Cc: Jonathan Isom, Michal Nazarewicz, linux-c-programming On Fri, Feb 11, 2011 at 03:18, ratheesh k <ratheesh.ksz@gmail.com> wrote: >>On Fri, Feb 11, 2011 at 4:56 AM, Jonathan Isom <jeisom@gmail.com> wrote: >> Newer distros use Native POSIX Thread Library (NPTL). They return the same pid. > > if linux treats every thing as task (both thread and process ) and > CLONE_PID flag is obsolete, i expected unique pid. POSIX.1 requires threads to share a couple of attributes (mainly process attributes) like the process ID, open FDs and many others. What you are referring to ("everything as task") is the fact that each thread is associated with a single scheduling entity within the kernel implementing a 1:1 mapping. Yet, threads created within the same process share a single PID. You are advised to consult pthreads(7) to make yourself familiar with the topic. Steve -- To unsubscribe from this list: send the line "unsubscribe linux-c-programming" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: same pid ? 2011-02-11 5:12 ` Steve Graegert (スティーブ) @ 2011-02-11 7:19 ` ratheesh k 2011-02-11 9:02 ` ratheesh k 0 siblings, 1 reply; 8+ messages in thread From: ratheesh k @ 2011-02-11 7:19 UTC (permalink / raw) To: Steve Graegert (スティーブ) Cc: Jonathan Isom, Michal Nazarewicz, linux-c-programming 2011/2/11 Steve Graegert (スティーブ) <graegerts@gmail.com>: > POSIX.1 requires threads to share a couple of attributes (mainly > process attributes) like the process ID, open FDs and many others. > What you are referring to ("everything as task") is the fact that each > thread is associated with a single scheduling entity within the kernel > implementing a 1:1 mapping. Yet, threads created within the same > process share a single PID. > Thanks steve. I found some more info. posix thread uses CLONE_THREAD with clone() system call. i quoted from - man clone CLONE_THREAD (since Linux 2.4.0-test8) If CLONE_THREAD is set, the child is placed in the same thread group as the calling process. To make the remainder of the discussion of CLONE_THREAD more readable, the term "thread" is used to refer to the processes within a thread group. Thread groups were a feature added in Linux 2.4 to support the POSIX threads notion of a set of threads that share a single PID. Internally, this shared PID is the so-called thread group identifier (TGID) for the thread group. Since Linux 2.4, calls to getpid(2) return the TGID of the caller. -Ratheesh > On Fri, Feb 11, 2011 at 03:18, ratheesh k <ratheesh.ksz@gmail.com> wrote: >>>On Fri, Feb 11, 2011 at 4:56 AM, Jonathan Isom <jeisom@gmail.com> wrote: >>> Newer distros use Native POSIX Thread Library (NPTL). They return the same pid. >> >> if linux treats every thing as task (both thread and process ) and >> CLONE_PID flag is obsolete, i expected unique pid. > > You are advised to consult pthreads(7) to make yourself familiar with the topic. > > Steve > ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: same pid ? 2011-02-11 7:19 ` ratheesh k @ 2011-02-11 9:02 ` ratheesh k 0 siblings, 0 replies; 8+ messages in thread From: ratheesh k @ 2011-02-11 9:02 UTC (permalink / raw) To: Steve Graegert (スティーブ) Cc: Jonathan Isom, Michal Nazarewicz, linux-c-programming Just to summarize ..... All processes in a thread group (i.e., different execution contexts of a process created by calling clone with CLONE_THREAD as we will see below) have a uniform thread group id (TGID). If a process does not use threads, its PID and TGID are identical. getpid() returns tgid in pthread implementation. we have uniquid tid for each thread, this could be returned using gettid(). -Ratheesh 2011/2/11 ratheesh k <ratheesh.ksz@gmail.com>: > 2011/2/11 Steve Graegert (スティーブ) <graegerts@gmail.com>: >> POSIX.1 requires threads to share a couple of attributes (mainly >> process attributes) like the process ID, open FDs and many others. >> What you are referring to ("everything as task") is the fact that each >> thread is associated with a single scheduling entity within the kernel >> implementing a 1:1 mapping. Yet, threads created within the same >> process share a single PID. >> > > Thanks steve. > > I found some more info. posix thread uses CLONE_THREAD with clone() > system call. > i quoted from - man clone > > CLONE_THREAD (since Linux 2.4.0-test8) > If CLONE_THREAD is set, the child is placed in the same thread > group as the calling process. To make the remainder of the discussion > of CLONE_THREAD more readable, the term "thread" is used to refer to > the processes within a thread group. > > Thread groups were a feature added in Linux 2.4 to support the > POSIX threads notion of a set of threads that share a single PID. > Internally, this shared PID is the so-called thread group identifier > (TGID) for the thread group. Since Linux 2.4, calls to getpid(2) > return the TGID of the caller. > > -Ratheesh > > > >> On Fri, Feb 11, 2011 at 03:18, ratheesh k <ratheesh.ksz@gmail.com> wrote: >>>>On Fri, Feb 11, 2011 at 4:56 AM, Jonathan Isom <jeisom@gmail.com> wrote: >>>> Newer distros use Native POSIX Thread Library (NPTL). They return the same pid. >>> >>> if linux treats every thing as task (both thread and process ) and >>> CLONE_PID flag is obsolete, i expected unique pid. >> > >> You are advised to consult pthreads(7) to make yourself familiar with the topic. >> >> Steve >> > ^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2011-02-11 9:02 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <AANLkTincdyMFR2Yb-HVvKmqoVTyTvSXweM5K_WLzFijC@mail.gmail.com>
2011-02-10 11:37 ` same pid ? ratheesh k
2011-02-10 12:22 ` Michal Nazarewicz
2011-02-10 18:09 ` ratheesh k
2011-02-10 23:26 ` Jonathan Isom
2011-02-11 2:18 ` ratheesh k
2011-02-11 5:12 ` Steve Graegert (スティーブ)
2011-02-11 7:19 ` ratheesh k
2011-02-11 9:02 ` ratheesh k
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).