script to write PIDs to a file

script to write PIDs to a file

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted!

  1. The problem statement, all variables and given/known data:

write a script that writes the PID of 2 different processes to a file every other time. as in pid a , pid b, pid a, pid b etc. then write a script that calculates the average runtime of 100 run throughs. (supposed to write a similar program in c that writes the PIDs aswell, to compare runtimes of the 2)
2. Relevant commands, code, scripts, algorithms:

bash
/usr/bin/time - built in gnu time thingy
octave - calculator for the time script

  1. The attempts at a solution (include all code and scripts):
 
#!/bin/bash
function child{
        for X in {0..6}
do
                echo "$$"
                sleep 1
        done
        return 0;
}
function parent{
        for I in {0..6}
 do
                echo "$$"
                sleep 1
        done
        return 0;
}
#Start child function
child &
 
# Start start parent function
parent

this was supposed to get me the 2 PIDs, but not even that seems to work. will redirect them once I get them to return correctly
getting this error when I try to run it as executable

./pidbash.sh: line 8: return: can only `return' from a function or sourced script
./pidbash.sh: line 9: syntax error near unexpected token `}'
./pidbash.sh: line 9: `}'
  1. Complete Name of School (University), City (State), Country, Name of Professor, and Course Number (Link to Course):
    Norwegian University of Science and Technology NTNU, Trondheim, Norway, Svein Erik Bratsberg, TDT4186 Operativsystemer, TDT4186 Operativsystemer
    Note: Without school/professor/course information, you will be banned if you post here! You must complete the entire template (not just parts of it).
function child {
....
....
function parent {

.........