Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

A long while ago I went to a job interview with a thoroughly weird company in London who claimed to be expert Unix consultants. Anyway these people were complete nutters and not surprisingly the company doesn't seem to be there any more, but at the interview they asked me the following question:

What is the first call you make to start a new process?

So I answered that the first call is fork. The two people interviewing me said (very insistently, as if I'd missed something utterly obvious)

What call do you do before you do the fork?

Now, I have no idea about this question, and I have to say these people convinced me they were unmitigated idiots for reasons completely unrelated to this question, but for some reason this question still bugs me even now. Is there some call which is made before a fork? Is there some subtlety I missed out on?

share|improve this question
add comment

3 Answers

up vote 5 down vote accepted

I hesitate to put this as an answer as one can only guess, but:

  1. flush stdout in case the child is going to do output prior to exec.
  2. close any open file descriptors greater than 2 assuming that the new process is expecting a "standard" environment as it would get from the shell.
  3. some obscure thing required by some obscure variant like Eunice that they though very clever of themselves to know.

Any way you scratch it, asking an obscure factual question is no way to derive anything about a candidate except perhaps how they respond to stupid questions.

share|improve this answer
2  
#2's wrong. You'd close unwanted handles after the fork, not before. The parent still needs them. –  Warren Young Sep 7 '10 at 7:06
    
They could be asking to see how you stand up for yourself when you're right but being challenged. –  Kevin Cantu Sep 9 '10 at 23:41
add comment

My guess is that

  • either they were thinking of something that's only applicable to a specific situation that they didn't bother to mention, like flushing buffers;
  • or they meant something you'd do after forking;
  • or they meant something you'd do before execve (which is the other half of spawning another program), expecting the answer fork, but they didn't really understand the whole thing and confused the two.
share|improve this answer
add comment

My guess is that they mean you should call 'pipe' to provide a way to allow the parent process to control the standard input or standard output of the child process. That's the most common call that occurs before a 'fork'.

I agree, that's a bad question. It would be a good question if they had specified that you were creating a process as part of a pipeline or something like that. It's important to know the order of operations -- create the pipe(s) before the 'fork', then close the opposing unused ends in each process, use 'dup2' to put the child's descriptors in the right place, calling some 'exec' function in the child, handling failures, and so on.

(The fact that it has experts guessing proves that it's a bad question.)

share|improve this answer
add comment

Your Answer

 
discard

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