LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Processes control, communication - kill next process and resume it (https://www.linuxquestions.org/questions/linux-newbie-8/processes-control-communication-kill-next-process-and-resume-it-4175448233/)

Hoxygen232 02-01-2013 03:55 PM

Processes control, communication - kill next process and resume it
 
Hi,

I made a C program that calls bash script files .sh by using "system(" ");", in this program the process father forks 3 processes (1. 2. 3.).
What I'd like to add to my program is:
- when the father forks the third process it does a "wait" ( wait (&status); )
- at that point the third process will be executing, but before executing it I want to use a script that gets the next (process 3.) process's PID in order to kill it.
- after that, the control returns to the father process (because its son has been killed), so the father has to restore the process 3. (that was previously killed) by using another script.sh!

That's it.
Summarizing, what I need to do is doing "processes concurrency"
I have to create processes that don't have to wait for other processes to finish, but they have to start meanwhile other processes make part of output available for them in order to use that output. In this way I will have "mutual communication" using "kill" bash command.

I hope it's clear!

Thanks

jpollard 02-02-2013 01:40 PM

Not clear.

Note - using the "system" function will wait until the command given is processed.

To execute that command the parent process forks and executes the shell, which then processes the command.

So if that command then causes three commands to be executed (such as a pipe), then it will wait for the last of those commands to finsh.

So the process tree is:
Code:

your-program
    \_ bash                -invoked by the system library function
        \_command3          -invoked by bash
            \_command2
                \_command1

BTW, this sort of sounds like a homework assignment...


All times are GMT -5. The time now is 07:58 AM.