have you just tried that command through the shell (maybe your provider doesn't allow shell access).
This should work just fine under any Linux derivative and most other unices as well.
here is my output so you know what you are looking for
[ereptur@mail ereptur]$ ps ax | grep "bash" | grep -v "grep" | awk '{print $1}'
13317
13359
13360
13361
as you can see, it returns all of the pids that bash is running as. Since your script should only have one invocation, this should only return one pid and therefore be able to pass this to the variable $pid. Using the exec command assures that you don't get other information back from the executed command other than the last line of output (which should be the correct pid number).
If you are using a third-part hosting company, it is also possible that they have disabled the use of the exec command. You may wish to check with them on this.