Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8922289
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T06:47:43+00:00 2026-06-15T06:47:43+00:00

I use fork() in order to make different proccesses running and printing a simple

  • 0

I use fork() in order to make different proccesses running and printing a simple message.The result of the code counfuses me though.. Take a look at the code:

#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <errno.h>
#include <math.h>
#include <sys/types.h>
#include <sys/ipc.h>
#include <sys/sem.h>
#include <time.h>


int main(void)
{

    fork();
    fork();
    fork();
    fprintf(stderr,"hello world\n");

}

and the output is:

mario@ubuntu:~/OS$ ./main
hello world
hello world
hello world
hello world
hello world
hello world
mario@ubuntu:~/OS$ hello world
hello world

mario@ubuntu:~/OS$ 

Note that i execute the program at the first line of the terminal but the output is not what i expected. Please help me! Thanks in advance! Same things happen if fprintf is changed with printf(“……”)

EDIT:I cant understand why the prints are this way. Six before the terminal line one next to it and 1 after it…

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T06:47:45+00:00Added an answer on June 15, 2026 at 6:47 am

    When the parent program exited, the shell running the parent program printed the shell prompt mario@ubuntu:~/OS$ on the screen. Any child program which had not printed it’s hello world by then would be printed after the prompt. If you want the prompt to not appear before all the hello worlds, you need to make the parent wait for all it’s child and grandchild programs to terminate.

    Check this to see how to make parent wait.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

What fork, or combination of packages should one to use to make PyPy, Django
I'm trying to make a homework assignment where I have to use fork() but
I've been trying to implement an online judge, but I'm stuck.. I use fork
How do you use the fork() command in such a way that you can
We use Subversion locally, and we're working on a project that uses a fork
Are there any counterindications to fork under mod_perl2? Should one use another way to
I need to use the fork() and wait() functions to complete an assignment. We
I am making a server and I use fork() for creating child processes but
I have homework that should use fork() and wait() system calls: 1) Write two
To learn how to use sockets, I've been working on a simple command-line chat

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.