How to Use the Linux wait Command for a Program Process

Click For Summary
To implement the Linux wait command for a program, it’s essential to clarify whether the program is written in C and involves forking child processes. The parent process must use functions like execl() and wait() or waitpid() to ensure it waits for the child processes to complete. If using system(), the command should return control to the parent, which can then check the return codes. The discussion emphasizes that child processes need to block on events or use interprocess communication methods for synchronization. Understanding the exact behavior of the child processes is crucial for effective implementation.
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 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 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
3K
Replies
4
Views
3K
Replies
1
Views
4K
  • · Replies 9 ·
Replies
9
Views
3K
Replies
9
Views
3K