A question about _thread_ of Linux

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi,

As we know, Linux implements thread as process, and a thread is merely
a process that shares certain resources with other processes.

But why the threads print the same process id?
Code like this:

void* print_pid(void* noused)
{
        printf("%u\n",getpid());

        return NULL;
}

int main()
{
        printf("%u\n",getpid());

        pthread_t thread_id;

        int ret=pthread_create(&thread_id, NULL, &print_pid, NULL);
        if(ret != 0 ){
                return 1;
        }

        pthread_join(thread_id, NULL);

        return 0;
}

--
Kernelnewbies: Help each other learn about the Linux kernel.
Archive:       http://mail.nl.linux.org/kernelnewbies/
FAQ:           http://kernelnewbies.org/faq/



[Index of Archives]     [Newbies FAQ]     [Linux Kernel Mentors]     [Linux Kernel Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]
  Powered by Linux