$! is set to the PID of the last process run in the background (means, with an & at the end or started with bg)
Off the top op my head I know no program or shell builtin to return the PID of the last program run, that's usually done in the program itself.