Forking C basics

Posted on 2011-10-10
Last Modified: 2012-08-14
Ok what I want to do is make a program that has a fork and takes a special action if it detects that it is the parent process.

How do I know when I am a parent.  This one is a pretty simple one I imagine so it'll be cheap.
Question by:GPicasso
    LVL 45

    Accepted Solution

    Hi G,

    The return value from the call to fork() tells you if you're the parent or the child.

      ID = fork ();
      if (ID == 0)
        // I'm the child process
        // I'm the parent process, the child's taskid is ID.

    Good Luck,
    LVL 13

    Expert Comment

    by:Hugh McCurdy
    Kdo is correct.

    You might also want to look at

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    An Outlet in Cocoa is a persistent reference to a GUI control; it connects a property (a variable) to a control.  For example, it is common to create an Outlet for the text field GUI control and change the text that appears in this field via that Ou…
    This is a short and sweet, but (hopefully) to the point article. There seems to be some fundamental misunderstanding about the function prototype for the "main" function in C and C++, more specifically what type this function should return. I see so…
    The goal of this video is to provide viewers with basic examples to understand recursion in the C programming language.
    The goal of this video is to provide viewers with basic examples to understand opening and reading files in the C programming language.

    759 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    9 Experts available now in Live!

    Get 1:1 Help Now