#!/usr/local/bin/perl -w use strict; use ExtUtils::testlib; use Solaris::Procfs qw(:procfiles writectl :control_codes :pcset_flags); use lib '.'; $|++; my $pid; if ($pid = fork()) { # parent # my $rc = waitpid($pid,0201); # Hardcoded flag. Aaack!! if ($rc < 0) { die "Process already exited"; } my $usage = usage($pid); my $realtime = $usage->{pr_rtime}->{tv_sec} + $usage->{pr_rtime}->{tv_nsec} / 1_000_000_000; my $usertime = $usage->{pr_utime}->{tv_sec} + $usage->{pr_utime}->{tv_nsec} / 1_000_000_000; my $systime = $usage->{pr_stime}->{tv_sec} + $usage->{pr_stime}->{tv_nsec} / 1_000_000_000; printf("real %.3f\nuser %.3f\nsys %.3f\n", $realtime, $usertime, $systime ); } else { # child # $|++; # Open the ctl file with a flag of 1, which means write-only. # sysopen(FILE,"/proc/self/ctl",1) or die "Could not open file /proc/self/ctl for writing: $!"; # Pack the flags into a series of signed long integers # my $flags = pack("l*",PCSET,PR_MSACCT); my $length = length $flags; # Now use syswrite to write the flags to the ctl file. # This turns on microstate accounting # syswrite(FILE,$flags,$length); close FILE; # Exec the target process # exec(@ARGV); }