LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
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 03-29-2011, 12:58 PM   #1
manohar
Member
 
Registered: Dec 2010
Posts: 42

Rep: Reputation: 2
Question CPU sharing between process and threads..?


Hi,

I have doubt regarding cpu sharing between process and threads.In my program iam creating 4threads=> 1 process+4 threads. How is cpu alloted to these all tasks. Is here process is getting cpu time like thread or having more cpu time than threads...!!
 
Old 03-29-2011, 05:56 PM   #2
Nominal Animal
Senior Member
 
Registered: Dec 2010
Location: Finland
Distribution: Xubuntu, CentOS, LFS
Posts: 1,723
Blog Entries: 3

Rep: Reputation: 948Reputation: 948Reputation: 948Reputation: 948Reputation: 948Reputation: 948Reputation: 948Reputation: 948
Quote:
Originally Posted by manohar View Post
I have doubt regarding cpu sharing between process and threads.
Process is a collection of resources like memory et cetera, and one or more threads. Thread is the thing that executes code, the thing that actually uses CPU time. A process does not.

When you run a program that does not do any thread-related stuff at all, you actually get a process which has one thread. If the program creates new threads, they are just like the original thread. (The threading library may create extra structures or do some internal tricks, but those are implementation details that do not really matter.)

In fact, there is no way to create a process without any threads. This is why people talking about a single-threaded process usually talk about the process only; the one thread is always implied, and does not need to be explicitly mentioned. (The one case, a "zombie process", happens when a process dies but no one cares (yet). The process identifiers and the exit status is kept, but everything else about the process is released. So even zombies are not really processes without threads, they're more like the remains of a process that has not completely died yet.)

Quote:
Originally Posted by manohar View Post
In my program iam creating 4threads=> 1 process+4 threads.
If you create four threads, e.g. by calling pthread_create() four times, you'll have five threads total. You can alter their relative priorities via e.g. pthread_setschedprio(), but by default, they are all equal, and get equal CPU time.

Some operating system kernels and/or threading libraries may adjust the priorities internally (temporarily) to ensure correct behaviour, or to optimize overall CPU use, so you cannot expect them to get exactly the same share.
 
  


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
Why is wine using both of my cpu threads? darkstarbyte Linux - General 2 12-28-2010 03:36 AM
process vs threads grob115 Linux - Newbie 1 10-04-2010 05:04 PM
CPU usage of each threads ufmale Programming 2 10-30-2009 05:50 PM
process and threads jkeertir Linux - Newbie 1 04-16-2009 11:01 AM
Threads And Process Penguinizer Programming 1 02-18-2003 09:39 PM

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

All times are GMT -5. The time now is 05:10 PM.

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