Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading