PERL: When does exec cause a pid switch?

My boss wrote some code (I know – dangerous territory) in perl years ago, and now it’s causing a problem – the pid changes, so the pidfile is no longer valid. Code:

exec($0, "-f", "$configfile")

I think there may be a shell invocation involved that is forking $0 (cloning probably), but he’s 1000% sure there’s no shell involved. Is there another explanation for another process (a different pid) instead of an actual exec’d program in the same pid, for the code above?

BTW

exec("exec", $0, "-f", "$configfile")

works fine (the exec’d process has the same pid as before the exec function call).

Also, if there is a shell involved, how can I prove to him that that’s the case?

Thanks!

>Solution :

There is no fork, because exec receives 3 arguments. From perldoc -f exec:

If there is more than one argument in LIST, this calls execvp(3)
with the arguments in LIST

Leave a Reply