Interview Question






Comment hidden because of low score. Click to expand.
9
of 9 vote

For Such Cases.We can Calculate the Output by one Formula

(2^(n) -1) + 1

I know Above expression is equal to 2^n then..I am trying to Explain tat (2^(n) -1) Child Process would be there and 1 is for Parent Process.

So 8 times Hello is getting printed
7 + 1 (7 Times by Child Process and 1 time by its parent)=8

Plz ignore Spelling and Grammar Mistakes

- User February 16, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Wow!! Looks like you put your solution in the code, instead of the print statement! =)

- TrippingBilly March 02, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

BTW, I'd say any combination of 8 sets of 'h' 'e' 'l' 'l' 'o' characters could be printed. The processes are not synchronized.

- kykydyk March 17, 2013 | Flag
Comment hidden because of low score. Click to expand.
2
of 2 vote

8 "hello" statements will be printed. Its 2^n. In this case 2^3.

- Junaid August 07, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
1
of 1 vote

For Such Cases.We can Calculate the Output by one Formula

(2^(n) -1) + 1

I know Above expression is equal to 2^n then..I am trying to Explain tat (2^(n) -1) Child Process would be there and 1 is for Parent Process.

So 8 times Hello is getting printed
7 + 1 (7 Times by Child Process and 1 time by its parent)=8

Plz ignore Spelling and Grammar Mistakes

- User February 16, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Explanation????

- Anonymous September 10, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

{f -fork, p - print

f ->f -> f ->p
f f p
f p ->p
p ->p
|
f ->p
p}

- amruthkesav.s September 16, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

sorry for the poor post
1) the parent invokes ffp (i), fp (ii), p
2) Now (i) invokes fp(iii),p
3) (ii) invokes p
4) (iii) invokes another p
There are 7 p's plus the parent prints once. So totally there are 8 "hellos" printed. Forking creates a child process and the excecution of the child process begins following the fork that is used to invoke it. So the output changes if the print statement position changes.

- amruthkesav.s September 16, 2011 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

int main()
{
int pid;
if(!fork()) {
printf("Hello world\n");
if(!fork()) {
printf("Hello world\n");
if(!fork()) {
printf("Hello world\n");
}
else
printf("Hello world\n");
}
else
printf("Hello world\n");
}
else
printf("Hello world\n");
return 0;
}

- Anonymous January 31, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

int main()
{
int pid;
if(!fork()) {
printf("Hello world\n");
if(!fork()) {
printf("Hello world\n");
if(!fork()) {
printf("Hello world\n");
}
else
printf("Hello world\n");
}
else
printf("Hello world\n");
}
else
printf("Hello world\n");
return 0;
}

- shan January 31, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

int main()
{
int pid;
if(!fork()) {
printf("Hello world\n");
if(!fork()) {
printf("Hello world\n");
if(!fork()) {
printf("Hello world\n");
}
else
printf("Hello world\n");
}
else
printf("Hello world\n");
}
else
printf("Hello world\n");
return 0;
}

- shan January 31, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

int main()
{
int pid;
if(!fork()) {
printf("Hello world\n");
if(!fork()) {
printf("Hello world\n");
if(!fork()) {
printf("Hello world\n");
}
else
printf("Hello world\n");
}
else
printf("Hello world\n");
}
else
printf("Hello world\n");
return 0;
}

- Anonymous January 31, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

int main()
{
int pid;
if(!fork()) {
printf("Hello world\n");
if(!fork()) {
printf("Hello world\n");
if(!fork()) {
printf("Hello world\n");
}
else
printf("Hello world\n");
}
else
printf("Hello world\n");
}
else
printf("Hello world\n");
return 0;
}

- shan January 31, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

For Such Cases.We can Calculate the Output by one Formula

(2^(n) -1) + 1

I know Above expression is equal to 2^n then..I am trying to Explain tat (2^(n) -1) Child Process would be there and 1 is for Parent Process.

So 8 times Hello is getting printed
7 + 1 (7 Times by Child Process and 1 time by its parent)=8

Plz ignore Spelling and Grammar Mistakes

- User February 16, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

For Such Cases.We can Calculate the Output by one Formula

(2^(n) -1) + 1

I know Above expression is equal to 2^n then..I am trying to Explain tat (2^(n) -1) Child Process would be there and 1 is for Parent Process.

So 8 times Hello is getting printed
7 + 1 (7 Times by Child Process and 1 time by its parent)=8

Plz ignore Spelling and Grammar Mistakes

- User February 16, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

For Such Cases.We can Calculate the Output by one Formula

(2^(n) -1) + 1

I know Above expression is equal to 2^n then..I am trying to Explain tat (2^(n) -1) Child Process would be there and 1 is for Parent Process.

So 8 times Hello is getting printed
7 + 1 (7 Times by Child Process and 1 time by its parent)=8

Plz ignore Spelling and Grammar Mistakes

- User February 16, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

For Such Cases.We can Calculate the Output by one Formula

(2^(n) -1) + 1

I know Above expression is equal to 2^n then..I am trying to Explain tat (2^(n) -1) Child Process would be there and 1 is for Parent Process.

So 8 times Hello is getting printed
7 + 1 (7 Times by Child Process and 1 time by its parent)=8

Plz ignore Spelling and Grammar Mistakes

- User February 16, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

For Such Cases.We can Calculate the Output by one Formula

(2^(n) -1) + 1

I know Above expression is equal to 2^n then..I am trying to Explain tat (2^(n) -1) Child Process would be there and 1 is for Parent Process.

So 8 times Hello is getting printed
7 + 1 (7 Times by Child Process and 1 time by its parent)=8

Plz ignore Spelling and Grammar Mistakes

- User February 16, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

For Such Cases.We can Calculate the Output by one Formula

(2^(n) -1) + 1

I know Above expression is equal to 2^n then..I am trying to Explain tat (2^(n) -1) Child Process would be there and 1 is for Parent Process.

So 8 times Hello is getting printed
7 + 1 (7 Times by Child Process and 1 time by its parent)=8

Plz ignore Spelling and Grammar Mistakes

- User February 16, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

main()
{
printf("hello");
main()
}

How many times it would print??

- zoya December 30, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

until stack over flow

- Arman September 02, 2014 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

Write the O/P of following code.
main(){
pintf(“HeloWorld\n”);
fork();
printf(“HeloWorld\n”);
}

- Anonymous March 06, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Write the O/P of following code.
main(){
pintf(“HeloWorld\n”);
fork();
printf(“HeloWorld\n”);
}

- Anonymous March 06, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
-2
of 2 vote

int main()
{
int pid;
if(!fork()) {
printf("Hello world\n");
if(!fork()) {
printf("Hello world\n");
if(!fork()) {
printf("Hello world\n");
}
else
printf("Hello world\n");
}
else
printf("Hello world\n");
}
else
printf("Hello world\n");
return 0;
}

- shan January 31, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
-2
of 2 vote

int main()
{
int pid;
if(!fork()) {
printf("Hello world\n");
if(!fork()) {
printf("Hello world\n");
if(!fork()) {
printf("Hello world\n");
}
else
printf("Hello world\n");
}
else
printf("Hello world\n");
}
else
printf("Hello world\n");
return 0;
}

- shan January 31, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
-2
of 2 vote

int main()
{
int pid;
if(!fork()) {
printf("Hello world\n");
if(!fork()) {
printf("Hello world\n");
if(!fork()) {
printf("Hello world\n");
}
else
printf("Hello world\n");
}
else
printf("Hello world\n");
}
else
printf("Hello world\n");
return 0;
}

- shan January 31, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

W+T+F

- Anonymous October 20, 2014 | Flag


Add a Comment
Name:

Writing Code? Surround your code with {{{ and }}} to preserve whitespace.

Books

is a comprehensive book on getting a job at a top tech company, while focuses on dev interviews and does this for PMs.

Learn More

Videos

CareerCup's interview videos give you a real-life look at technical interviews. In these unscripted videos, watch how other candidates handle tough questions and how the interviewer thinks about their performance.

Learn More

Resume Review

Most engineers make critical mistakes on their resumes -- we can fix your resume with our custom resume review service. And, we use fellow engineers as our resume reviewers, so you can be sure that we "get" what you're saying.

Learn More

Mock Interviews

Our Mock Interviews will be conducted "in character" just like a real interview, and can focus on whatever topics you want. All our interviewers have worked for Microsoft, Google or Amazon, you know you'll get a true-to-life experience.

Learn More