How to determine if a script is running on a system or a qx call in Perl?

In Perl, you can determine if a script is being executed in another script (presumably through systemor qx)?

$ cat foo.pl
print "foo";
print "\n" if not $in_qx;  # or the like.

I understand that this is not applicable if the script was executed through exec.

I know exactly what systemstarts the process like fork, and I know that it forkcan return a value that is variable depending on whether you are in the parent or child process. I don’t know about qx.

Regardless, I'm not sure how to determine if I have an forked process without actually executing fork.

+3
source share
3 answers

( init). , open, qx//, open2 open3 isatty POSIX, , system, , (, system "nohup", "./foo.pl" perl- ).

+6

" ", "getppid" ( ). , perl script pgrep .

+5

? , . --isforked.

+2

Source: https://habr.com/ru/post/1709712/


All Articles