Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I was asked these questions in interview (C++ interview). I'm not confident of the answers and would like to know more.

  1. Can thread create another thread ?
  2. Can process create another process ?
  3. Can thread create a process ?
  4. Can process create a thread ?
share|improve this question
    
for ques. 1 and 4 answer is YES. –  Harry Joy Feb 2 '11 at 6:04
add comment

2 Answers

  1. Yes, a thread can create another thread. On UNIX this is done (at the low level) through the clone() command, and at the high(er) level, in C coding, through the pthread library.

  2. Yes, a process can launch another process. This happens all the time. The most common type of process -> process is through fork().

  3. This, I'm unsure. At this point I'd like to mention there are two major types of threads: kernel-level threads and user-level threads. Kernel level threads (in general) are tied to major processes, while user level threads are spawned by these processes (so by kernel level threads). There are exceptions Maybe someone can give a better answer to thread -> process.

  4. Yes. See the comment in 3.

share|improve this answer
    
0) The question states windows, yet you have UNIX calls 1) clone() is Linux specific, it is not generic UNIX. 2) fork() is not just hte most common, but the only way to spawn a process on UNIX (vfork() just calls fork on most systems) 3) yes, a thread can call fork, but you confuse the issue kernel vs user threads. –  Rich Homolka Feb 2 '11 at 17:16
    
I don't remember the Windows tag being there when I answered. I might have missed it inadvertently, sorry. –  aqua Feb 3 '11 at 1:19
add comment

Any code that executes can do anything.

That said, processes aren't code -- threads are the things that are actually run, and processes are their enclosing environments. Hence (1) and (3) are true, the rest false.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.