How to Use the Linux wait Command for a Program Process

Click For Summary

Discussion Overview

The discussion revolves around the implementation of the Linux wait command within a program, specifically focusing on how a parent process can manage child processes created through the system command. The scope includes technical explanations and potential challenges faced in programming, particularly in C.

Discussion Character

  • Technical explanation
  • Debate/contested

Main Points Raised

  • One participant seeks clarification on how to implement the wait command for child processes generated by the system command.
  • Another participant questions whether the command is being executed correctly, suggesting that some commands are shell builtins that require proper invocation through the shell.
  • A participant proposes that if the user is writing a C program, a combination of execl() and wait() (or related functions) should be used, while also advising to check return values carefully.
  • Concerns are raised about the children processes not waiting as expected, with emphasis that the parent process is the one that waits for the children.
  • It is suggested that for children to wait, they must block on events like I/O waits or synchronization mechanisms such as mutexes or semaphores controlled by the parent.
  • Some participants use humor to illustrate the challenges of managing processes, comparing it to parenting difficulties.

Areas of Agreement / Disagreement

Participants express differing views on the effectiveness of the methods discussed for managing child processes. There is no consensus on the best approach, and the discussion remains unresolved regarding the implementation details.

Contextual Notes

Participants have not fully clarified the specific behaviors or requirements of the child processes, which may affect the implementation of the wait command.

Quatros
Messages
17
Reaction score
1
Moved from technical forum, so no template
I want to know how to implement a wait(linux) command for my program. Our professor allowed us to generate any command with system to generate a process. However, when I attempt to do this, I can see the processes that are kids on my terminal, however I can't make them wait.
 
Physics news on Phys.org
I don't think parent has successfully gotten their kids to wait but they try.

So are you sure the command is being executed via system? There are some commands which are actually shell builtins that require you to use system to invoke the shell and the shell invokes your
command.

system("sh ls -al");

Or something like that.
 
Quatros said:
I want to know how to implement a wait(linux) command for my program. Our professor allowed us to generate any command with system to generate a process. However, when I attempt to do this, I can see the processes that are kids on my terminal, however I can't make them wait.
Let's be clear what you're trying to do. Are you writing a program in C, which forks a child process, and then the parent process must wait for the child? If so, then a combination of execl() and wait() [or waitpid(), or waitid()] should suffice, provided you check both return values carefully. If you use system(), then you can simply let system() return and look at its return codes. Check your Linux man page for system(). Mine has an example that does pretty much what (I think) you want.

If that's not what you're trying to do, then please explain more clearly.

(Btw, if this is homework, then you should post this in the "Engineering & Computer Science" homework forum, and use the homework template. I.e., post the question verbatim -- exactly as it was given to you.)
[Edit: I see this thread has now been moved.]
 
Last edited:
The children do not wait with either what strangerep showed you, or jedishfru showed. The PARENT process waits for the kids.

If you have "kids" that are supposed to wait, then each kid has to block on one of these:

An event like an I/O wait on a pipe - usually the kid reads from stdin on a pipe that the parent writes to.

A mutex or a semaphore is controlled by the parent, there is a shared memory object or a stream or other object used for inteprocess communication that the parent writes and maybe reads, and the child read and maybe writes. The kids are usually threads (lightweight proceses), part of the pthread library.

So you to need to inform us what your kids are really doing.
 
jim mcnamara said:
The children do not wait with either what strangerep showed you, or jedishfru showed. The PARENT process waits for the kids.

To be clear, I was talking about real parents and their inability to get their kids to wait on anything. Parenting can be like herding cats.
 
  • Like
Likes   Reactions: jim mcnamara
jedishrfu said:
To be clear, I was talking about real parents and their inability to get their kids to wait on anything. Parenting can be like herding cats.
Yeah, computer operating systems are like that as well.
 
  • Like
Likes   Reactions: jedishrfu

Similar threads

  • · Replies 1 ·
Replies
1
Views
5K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 10 ·
Replies
10
Views
2K
Replies
3
Views
2K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 9 ·
Replies
9
Views
4K
Replies
4
Views
3K
Replies
1
Views
4K
Replies
9
Views
3K
  • · Replies 9 ·
Replies
9
Views
3K