LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 04-10-2013, 10:56 AM   #1
visu_kvg
LQ Newbie
 
Registered: Aug 2009
Location: HYD,India
Distribution: RHEL
Posts: 19

Rep: Reputation: 0
The difference between process and thread


Hi LQ,

I am a sys admin. I can't totally understand system calls and other programming stuff. However, I am good at using top, ps, kill, mpstat, vmstat.... and other linux commands.
I want to understand the difference between process and thread using the above commands which I am good at.

I would be really happy if you guys have any ideas!!

Thanks.

Last edited by onebuck; 04-17-2013 at 11:09 AM. Reason: correct title
 
Old 04-10-2013, 12:12 PM   #2
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 26,636

Rep: Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965
Quote:
Originally Posted by visu_kvg View Post
Hi LQ,
I am a sys admin. I can't totally understand system calls and other programming stuff. However, I am good at using top, ps, kill, mpstat, vmstat.... and other linux commands. I want to understand the difference between process and thread using the above commands which I am good at.
Using those commands is pointless, unless you understand what they give you.
http://en.wikipedia.org/wiki/Thread_...from_processes
 
Old 04-16-2013, 07:53 AM   #3
tarunchawla
Member
 
Registered: Mar 2010
Location: New Delhi,India
Distribution: Ubuntu 14.04
Posts: 117

Rep: Reputation: 3
Each process has its own address space but threads of a same process have same address space. Address space is memory area in which instructions are executed and data is stored. Each process has a large set of metadata such as PC(program counter which stores next instruction to be executed) and to move to next process we have to move out current process while it has not completed its task.When we switch from a one process to another process then before switching to other process we have to store some data related to that process so that when we switch back to that process we can start from where we left. So process switching is costly in terms of memory & processing. If some metadata is common for all executing instance then that executing instance is thread which is actually a process but shares more data with other threads which are related to this thread.So we say that threads which are related is classified in a single process(We commonly say that threads are a part of single process). Now we have the benefit that when we switch from one thread to other much less overhead for data storage & context switching is there. When we encounters two tasks having some strong relation with each other we put them into one process as threads.

This is just a overview ,other things you can google.
Regards ,
Tarun
 
Old 04-16-2013, 09:18 AM   #4
johnsfine
LQ Guru
 
Registered: Dec 2007
Distribution: Centos
Posts: 5,286

Rep: Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197
Quote:
Originally Posted by tarunchawla View Post
Each process has its own address space but threads of a same process have same address space.
Good start. But I think your description got both less accurate and less understandable after that. I would advise the OP to stop reading your post after that first sentence.

Quote:
...
When we encounters two tasks having some strong relation with each other we put them into one process as threads.
I'm having trouble guessing what you might mean by "we encounters". It is especially hard to find a meaning that makes that sentence correct.

From the point of view of selecting one or the other in adding parallelism to an application design, the big difference between threads and processes is that multiple threads within a process share that process's address space.

Two processes can share memory that is mapped into each of their address spaces. So even that big difference is not an absolute design constraint in choosing multiple threads vs. multiple processes.

There is a big overhead to creating, maintaining, and eventually deleting and address space. So having multiple processes has more overhead than multiple threads within a process.

But the design decision between the two usually comes down to shared memory.

With multiple threads in one process, it takes extra programming effort every time you want to not share some memory between threads. For example, there are often static or global variables that would cause conflicts if freely shared and don't really need to be shared at all: Things would be simpler if each thread just had its own copy. It is possible to set up such thread local replacements for static or global variables, but it is significant extra work. Often it is easier to use locking to control sharing even though there is no underlying benefit to having that sharing (vs. private copies).

With multiple processes, memory by default is not shared. Static and global variable are private to each process and you need extra effort everywhere you do want to share memory.

Last edited by johnsfine; 04-16-2013 at 09:27 AM.
 
  


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 On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Difference between Child THREAD and Child PROCESS whho Linux - Newbie 12 02-16-2015 12:22 AM
difference between init.rc process and normal process manohar Programming 1 03-31-2011 11:17 PM
difference between an AIX thread and Linux thread sanjeebkdeka AIX 1 02-11-2010 09:37 AM
Get Process size and Thread count for a particular running process haseit Linux - Newbie 2 01-22-2009 11:09 PM
What is the diff betwn mke2fs and tune2fs ? sambyte Linux - Newbie 5 03-03-2006 06:57 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 04:50 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