Tag Info

New answers tagged

2

If the time to start a shell is negligible compared to the time it takes to run the command, you can run an intermediate shell, and use the exec builtin to ensure that a.out replaces the shell rather than being executed as a subprocess. time sh -c 'echo $$; exec ./a.out'


1

It's possible by writing a small shell fragment that runs the remainder of its command line as a child process, capturing that child's PID as a side-effect. Here's a script that will do that for you (error checking omitted for brevity) #!/bin/sh # "$@" & CHILD=$! echo "$CHILD" >/tmp/mychild.pid echo "INFO: child is $CHILD" >&2 wait If you ...


2

By definition, a.out is a child process of time. So time is the parent pid of a.out! here's a test where I replace a.out with sleep 60: $ time sleep 50 & timepid=$! $ aoutpid=$(pgrep -P $timepid) $ ps -o ppid,pid,start,cmd w -p $$,$timepid,$aoutpid PPID PID STARTED CMD 2065 2068 21:34:57 -bash 2068 3297 22:16:05 -bash 3297 3298 22:16:05 sleep 50 ...


1

Job control lets you put it in the background and get it back in foreground again: time ( set -m; sleep 10 & echo $! ; fg >/dev/null ; ) Hmm … the complete command winds up as a stopped job, though. Odd. Here's a workaround: bash -c ' time ( set -m; sleep 10 & echo $! ; fg >/dev/null ; ) ' Of course, by then it might as well be: bash ...


1

Try pgrep to find the PID: pgrep -l "a.out" Read map pgrep to get more idea.


1

As the ultimate in non-fancy approaches, every-time i login (approximately once a day) my .bashrc runs this: sudo rdate time-b.timefreq.bldrdoc.gov && hwclock -w I did a little testing a year or so ago and it apparently kept my main computer within one second of official time. and yes, it should just be made into a line of a cron job, but there ...


2

To me, NTP is the obvious answer. Reliable and consistent - assuming some sort of Internet connection, with an option that's enabled on many distributions to set the clock directly during the boot-up process. However, this is an opinion-based answer, probably not suited to SE.


1

The CPU is available for other uses while disk I/O occurs, so it doesn't count towards a process's CPU time (the user and sys figures). That's because, as you guessed, that operation is happening in the disks (likely in more or more microcontrollers soldered to the disk's boards)


2

Bash's built-in time returns the exit status of the command. You can test that fairly easily with time false; afterwards, echo $? prints 1 as expected. You can also test something with a different exit code to confirm other codes are preserved: $ time bash -c 'exit 42'; echo "Exit code: $?" real 0m0.002s user 0m0.000s sys 0m0.000s Exit code: 42


1

The step method sets the clock instantly. How long could SNTP take to complete slewing? I am not experienced with SNTP solutions, so assume they are not different from full-fledged NTP in this regard. As for the former, it uses two turnkey limits: 128 ms for stepping and 500 ppm (496 to 512 ppm) for locking and slewing. That means that the maximum ...



Top 50 recent answers are included