0

I have a script that has many sequential steps to perform, some of which are written into some child scripts. The child scripts run in sequence only.

  1. Is there a way to halt an already running parent process/script that is waiting for exit status of child script?
  2. Is there a way to execute a script with ppid of the parent process/script?
  3. Is there a way to then pass the exit status of a child script to the already running yet waiting parent script?

Suppose a child process/script has become defunct or it is going to perform some steps that need modification. so i can run the modified child script in background, halt the parent script and then i can kill the original child script and continue parent script whilst passing the success code to the parent. I intend to do the above procedure after the parent script has already started its execution.

If i kill the child script, the parent fails. Thus either i have to edit the parent script and rerun, or perform all the steps of the parent again after undoing the processing done earlier by parent. Its a lot time consuming.

madD7
  • 101
  • The way I understand the third point is that you want to change the behavior of a child script as it is running. Can you provide some details on your use case and explain this a bit further? – Haxiel Jul 25 '20 at 07:56
  • I may want to modify as it is running, or may be perfom steps manually or skip the execution, yet provide success as exit status to parent script. the scripts generally have database activities, dumping some data into files which are then sftp or scp to a chain of servers. The data processing on the database has a lot of filters, joins etc. – madD7 Jul 25 '20 at 08:33
  • Okay, how about removing the parent-child link? You could block the parent script at the appropriate step, using a read command (see https://unix.stackexchange.com/q/134437/173368). Then you do the intermediate tasks in however way you see fit. Once done, go back to original script and let it resume and run to completion. – Haxiel Jul 25 '20 at 11:23
  • Although my answers below answer your 3 questions i have a feeling it doesn't provide you with the info you were looking for. Write some pseudocode and describe the expected so that i can see what you really want. – Garo Jul 25 '20 at 15:54

1 Answers1

0
  • Question 1:
#!/bin/bash
echo "I am the parent process and will launch a child and wait until it's finished"
/path/to/child.sh
echo "The child has finished and it's exitstatus is: $?"
  • Question 2: In theory it's not possible. In practice you emulate this behaviour. If you fork and treat the child as the parent and the parent as the child then the 'new parent' will have the PPID it of the 'old parent'

  • Question 3: The exit status of the child will (in bash and most shells) end up in the var $? of the the parent. See the script in my answer to question 1.

Garo
  • 2,059
  • 11
  • 16
  • Does answer the question, but assumes that i am yet to write the parent-child scripts. The question(s) is/are asked considering the scenario where the scripts are already under execution. – madD7 Jul 27 '20 at 09:03
  • Can you give a example of what you want to achieve in another programming language (or just in pseude-code) ? – Garo Jul 27 '20 at 12:27
  • not in another language. its in shell scripting. – madD7 Jul 27 '20 at 12:40