[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now


Forking C basics

Posted on 2011-10-10
Medium Priority
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 46

Accepted Solution

Kent Olsen earned 200 total points
ID: 36945155
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
ID: 36945228
Kdo is correct.

You might also want to look at     http://www.manpagez.com/man/2/fork/

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Windows programmers of the C/C++ variety, how many of you realise that since Window 9x Microsoft has been lying to you about what constitutes Unicode (http://en.wikipedia.org/wiki/Unicode)? They will have you believe that Unicode requires you to use…
Examines three attack vectors, specifically, the different types of malware used in malicious attacks, web application attacks, and finally, network based attacks.  Concludes by examining the means of securing and protecting critical systems and inf…
The goal of this video is to provide viewers with basic examples to understand how to use strings and some functions related to them 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.
Suggested Courses

834 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