Skip to content
Advertisement

Creating three children in C that have the same parent

My problem is that the children does not have the same parent and does not appear correctly, here is my code:

JavaScript

As of right now when i run the program i will get this as output in bash, where bash has the PID of 11446:

JavaScript

How do i get the first child to appear first, second child to appear second and the third child to appear last, and get all the children to have the PPID 28753

Advertisement

Answer

From man fork:

RETURN VALUE
On success, the PID of the child process is returned in the parent, and 0 is returned in the child. On failure, -1 is returned in the parent, no child process is created, and errno is set appropriately.

Your ifelse conditions are swapped.

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement