forking a child process and kill its parent to show that child process has init() as its parent

Hi everyone

i am very new to linux , working on bash shell.
I am trying to solve the given problem

  1. Create a process and then create children using fork
  2. Check the Status of the application for successful running.
  3. Kill all the process(threads) except parent and first child (if the Application have threads).
  4. Now kill the parent, check the status of child process which will be orphan now and check that it will taken by init process.
  5. Kill the application

i need lead in this script .. help

Show your efforts so far, thanks.

---------PARENT SCRIPT (have to run in background sh parent.sh &)------------------

sh child1.sh

--------- child script -----------------

ps -eaf | tail

for i in `ps -ef | grep parent.sh | grep -v grep | awk '{print $2}'`
do
	 echo "parent.sh pid = $i"
	ps -eaf | tail
done


for j in `ps -ef | grep child | grep child1.sh | aek '{print $2}'`
do 
	echo "child1.sh pid = $j"
done
 


pid = $`ps -o user, pid , ppid -ax | grep parent |awk '{print $2}'`

for k in $`ps - o user , pid , ppid -ax`
do 
 if [$pid = $i,$j]
	echo "parent or child process"
 else 
     kill -9 $pid
#fi

what i am trying is running is -
running a child script in parent script
and in child script i want to collect all the process pid's that are initiated from parent.sh
and kill them all except for parent process and child process..

after that i am trying to display on terminal that when i will kill the parent process , child process will be having init as it parent