I have a perl script that calls external executables using system()
. I would like to measure the CPU seconds taken by these external programs. Ideally, I would like
$ time ( ls ) 2> er ## works
$ perl -e 'system("time (ls)")'
sh: 1: Syntax error: word unexpected (expecting ")")
The problem is that in first case, your shell is probably /bin/bash
whereas in second case it is /bin/sh
. If you want to run your command with another shell, you could use system LIST form:
system("/bin/bash", "-c", "time(ls)")
Note 1: There's PERL5SHELL
environmnet value, but that seems to take effect only on Win32.
Note 2: If you want to measure CPU time of child process, you could use Unix::Getrusage or BSD::Resource modules.