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 9242309
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T08:33:18+00:00 2026-06-18T08:33:18+00:00

Possible Duplicate: fork() and output by running: #include<stdio.h> int main() { fork(); printf(b); if

  • 0

Possible Duplicate:
fork() and output

by running:

#include<stdio.h>
int main()
{
    fork();
    printf("b");
    if (fork() == 0) {
        write(1, "a", 1);
    }else{
        write(1, "c", 1);
    }
    return 0;
}

I got cbcabbab, could someone explain the output to me? And if possible, is there a tool to see the running procedure step by step?

  • 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-18T08:33:19+00:00Added an answer on June 18, 2026 at 8:33 am

    Try running it again, you’ll probably get a different output.

    As for a tool to see the procedure step by step, I think strace -f might help a bit:

    $ strace -f ./weirdfork
    execve("./weirdfork", ["./weirdfork"], [/* 35 vars */]) = 0
    ... uninteresting boiler plate removed ...
    clone(Process 8581 attached
    child_stack=0, flags=CLONE_CHILD_CLEARTID|CLONE_CHILD_SETTID|SIGCHLD, child_tidptr=0x7fe1c7d0b9d0) = 8581
    [pid  8580] fstat(1, {st_mode=S_IFCHR|0620, st_rdev=makedev(136, 0), ...}) = 0
    [pid  8581] fstat(1, {st_mode=S_IFCHR|0620, st_rdev=makedev(136, 0), ...}) = 0
    [pid  8580] mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0 <unfinished ...>
    [pid  8581] mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0 <unfinished ...>
    [pid  8580] <... mmap resumed> )        = 0x7fe1c7d22000
    [pid  8581] <... mmap resumed> )        = 0x7fe1c7d22000
    [pid  8581] clone( <unfinished ...>
    [pid  8580] clone(Process 8582 attached
     <unfinished ...>
    [pid  8581] <... clone resumed> child_stack=0, flags=CLONE_CHILD_CLEARTID|CLONE_CHILD_SETTID|SIGCHLD, child_tidptr=0x7fe1c7d0b9d0) = 8582
    Process 8583 attached
    [pid  8580] <... clone resumed> child_stack=0, flags=CLONE_CHILD_CLEARTID|CLONE_CHILD_SETTID|SIGCHLD, child_tidptr=0x7fe1c7d0b9d0) = 8583
    [pid  8580] write(1, "c", 1 <unfinished ...>
    [pid  8581] write(1, "c", 1cc)            = 1
    [pid  8580] <... write resumed> )       = 1
    [pid  8581] write(1, "b", 1b <unfinished ...>
    [pid  8580] write(1, "b", 1 <unfinished ...>
    [pid  8581] <... write resumed> )       = 1
    b[pid  8581] exit_group(0)               = ?
    Process 8581 detached
    [pid  8580] <... write resumed> )       = 1
    [pid  8580] exit_group(0)               = ?
    [pid  8583] write(1, "a", 1 <unfinished ...>
    [pid  8582] write(1, "a", 1a)            = 1
    a[pid  8582] write(1, "b", 1 <unfinished ...>
    [pid  8583] <... write resumed> )       = 1
    [pid  8583] write(1, "b", 1b)            = 1
    [pid  8583] exit_group(0)               = ?
    Process 8583 detached
    b<... write resumed> )                   = 1
    exit_group(0)                           = ?
    Process 8582 detached
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: Working of fork() in linux gcc #include <stdio.h> void main () {
Possible Duplicate: Java - C-Like Fork? I have a static void main with this:
Possible Duplicate: How is it possible for fork() to return two values? I'm new
Possible Duplicate: Are file descriptors shared when fork()ing? Suppose I have following code in
Possible Duplicate: Can main function call itself in C++? I found this problem very
Possible Duplicate: Working of fork() in linux gcc Why does this code print two
Possible Duplicate: Learning to write a compiler I looked around trying to find out
Possible Duplicate: Can you write object oriented code in C? Hi, can someone point
Possible Duplicate: C++ convert int and string to char* Hello, i am making a
Possible Duplicate: Unix fork() system call what runs when? I looked on Wikipedia, and

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.