# Tag Info

13

There's a library called libfaketime which allows you to make the system report a given time to your application. You can either have the system report a fixed time for the duration of the program execution, or start the clock at some specific time (for example, 01:59:30). Basically, you hook the faketime library into your program's in-memory image through ...

11

You can use the command shell built-in to bypass the normal lookup process and run the given command as an external command regardless of any other possibilities (shell built-ins, aliases, etc.). This is often done in scripts which need to be portable across systems, although probably more commonly using the shorthand \ (as in \rm rather than command rm or ...

11

If I understand what you're asking for I this will do. I'm using the commands ls ~ and tee as stand-ins for ./foo and bar, but the general form of what you want is this: $( time ./foo ) |& bar NOTE: The output of time is already being attached at the end of any output from ./foo, it's just being done so on STDERR. To redirect it through the pipe you ... 10 By using strace, I saw that the line number=$(expr $number + 1) causes a fork, path search, and exec of expr. (I'm using bash 4.2.45 on Ubuntu). That filesystem, disk, and process overhead led to bash only getting around 28% of the CPU. When I changed that line to use only shell builtin operations ((number = number + 1)) bash used around 98% of the ... 9 .INIT. 16 u That's not fine. You either queried the state to soon, or your ntpd can't connect to those servers at all. When it is synced, it should display IP addresses or host names in the refid column, and values like 2 or 3 in the st column. The output of a working ntpd should look like this: iserv ~ # ntpq -p remote ... 8 "Real" time is elapsed time, which is usually the difference between wall clock times, but not always. For example, if you start a process at 01:59:00 on the day in which daylight-savings (summer) time takes effect in a locale in which the time change is at 02:00, and the process takes two minutes, then the real elapsed time will be two minutes, while the ... 7 In many shells including ksh, zsh and bash, time is a keyword and is used to time pipelines. time foo | bar Will time both the foo and bar commands (zsh will show you the breakdown). It reports it on the shell's stderr. time foo.sh > bar.txt Will tell you the time needed to open bar.txt and run foo.sh. If you want to redirect time's output, you ... 7 time sudo command executes your shell's time builtin if it has one, whereas sudo time command always executes the time executable in the program search path ($PATH). time sudo command includes the time taken by the sudo command, whereas sudo time command doesn't. You should use sudo time command, because sudo's processing time is small but not always ...

6

As per the GNU date manpage: By default, date pads numeric fields with zeroes. The following optional flags may follow '%': - (hyphen) do not pad the field Therefore you can do alias date = date +"%Y.%-m.%-d.%-H.%-M.%-S" and receive 2013.6.14.3.19.31

6

You can find out when a file was modified, and you can find out who owns it, but there's no guarantee that the owner is the one who modified it. Write permission can be granted to other users, and there's usually no record of who modified a file. I said "usually" because there is an audit system that can keep that kind of record, but it's not activated in a ...

6

There is a shortcut in bash to sidestep keywords, without having to specify a path or use another builtin like command: Escape it with a backslash. =^_^= izkata@Izein:~$time real 0m0.000s user 0m0.000s sys 0m0.000s =^_^= izkata@Izein:~$ \time Usage: time [-apvV] [-f format] [-o file] [--append] [--verbose] [--portability] ...

5

I'm assuming you understand that both these commands are calling a different version of time, right? bash's built-in version % time GNU time aka. /usr/bin/time % \time The built-in time command to bash can be read up on here: % help time time: time [-p] PIPELINE Execute PIPELINE and print a summary of the real time, user CPU time, and system ...

5

If you just want to convert existing syslog files you can e.g. use a small python/perl/ruby program to change Tue Apr 23 07:23:24 EDT 2013 in something with UTC (or CET). If you want to have more control over the time format that is written in the log file, you might want to look at syslog-ng. Its tsformat() function allows you to configure the time format ...

5

The same way you'd time any other shell command: use the time command. $time pg_restore ... real 1m0.000s user 1m0.000s sys 0m0.000s Here, real is the elapsed wall clock time, which is probably the only meaningful value, since most of the work is being done in a separate process (the PostgreSQL server). 5 Assuming it is a shell script, this should work: while [$(date +%H:%M) != "04:00" ]; do sleep 1; done That's for 24 hour times. If you want this to continue both at 4:00 AM and 4:00 PM, use this instead: while [ $(date +%I:%M) != "04:00" ]; do sleep 1; done 5 Tip for debugging what's going on I would suggest turning on the debug facility of your shell, assuming you're using Bash.$ set -x This output will show you what's happening behind the scenes when you run a command that produces this output. The output That output is from the time /usr/bin/time command being prefixed to every command you run. In order ...

5

Correct, usually shell built-ins have help pages instead since their usage isn't usually that involved. If the built-in commands were all that complicated, there would have likely been an effort to simplify shell logic by pushing that functionality into its own executable, at which point it would get a man page. You can get information on time by using ...

5

No. Process/context switches aren't free. How much other processes running will slow yours down is very system-dependent, but it consists of things like: Every time a processor switches to a different address space (including process), then the MMU cache must be flushed. And probably the processor L1 caches. And maybe the L2 and L3 caches. This will slow ...

5

time sends its output to stderr instead of stdout by default. You just need to redirect that where you want it. You say "On the other hand, if I wanted to time foo, and redirect the output of time I could write, time (./foo) | bar." but this is actually incorrect. In this case, the output of time would still be displayed on your console, only stdout would ...

4

Have you read the documentation on the Arch wiki? https://wiki.archlinux.org/index.php/Time The hardware clock can be queried and set with the timedatectl command. To change the hardware clock time standard to localtime use: # timedatectl set-local-rtc 1

4

use time: $time longrunningcommand --takeyourtime time is a bash builtin. if you want to use the system time do it like this:$ /usr/bin/time longrunningcommand --getsomecoffee or like this: $\time longrunningcommand --callmom 4 That won't work. The number of clock cycles each instruction takes to execute ( they take quite a few, not just one ) depends heavily on the exact mix of instructions that surround it, and varies by exact cpu model. You also have interrupts coming in and the kernel and other tasks having instructions executed mixed in with yours. On top of that, the ... 4 When you're running it in the shell, you're actually using the bash built-in function, which looks like this: anthony@Zia:~$ time perl -e 'sleep 1' real 0m1.003s user 0m0.000s sys 0m0.004s Cron isn't using the bash built-in; it's using /usr/bin/time: anthony@Zia:~$/usr/bin/time perl -e 'sleep 1' 0.00user 0.00system 0:01.00elapsed 0%CPU ... 4 On most systems, you can use the ulimit command when you start the program to limit the amount of CPU time it can use. Under the hood, this calls setrlimit with the argument RLIMIT_CPU. After the program has used that much time, the program is killed. (ulimit -t 3600; myprogram) You can refine further by setting a soft limit after which the program ... 3 time is a reserved word in zsh. It is only recognized at the beginning of a command. It's a reserved word, and not a builtin, because when you write time foo | bar, it is the compound command foo | bar that is timed and not just foo. Where time isn't recognized as a reserved word, it's interpreted as the name of an external command. Your system, for ... 3 Not all versions of time support the -o and --output arguments. You will want to run the command like this: (time script.sh) 1> /dev/null 2> /tmp/logFile This will put the output of script.sh into /dev/null and the results to /tmp/logFile. If you want both STDERR and STDOUT to go to the log file you can run it like this: (time script.sh) ... 3 Just to illustrate what has been said, with a two threaded processes doing some calculation. /*a.c/* #include <pthread.h> static void * dosomething () { unsigned long a,b=1; for (a=1000000000; a>0; a--) b*=3; return NULL; } main () { pthread_t one, two; pthread_create(&one,NULL, ... 3 BASH isn't that bad for this problem. You just need to use the very powerful, but underused date command. for i in {1..10}; do hrmin=$(date -u -d@$(($i * 10 * 60)) +"%H:%M") outfile=${hrmin/:/-}.mp4 ffmpeg -i video.mp4 -ss${hrmin}:00 -t 00:10:00 -c copy ${outfile} done date Command Explained date with a -d flags allows you to set which date you ... 3 Since$GPSDATE is being reported as Sun Aug 8 06:08:11 PKT 2010 the date -s command is doing exactly what you are telling it to do. Why is it reporting a wrong year (or nothing at all)? I have no idea. Since you are already using ntpd why are you not content to let NTP do its thing? Is this an "I'd like gpsdate to work because it is there" issue? The ...

Only top voted, non community-wiki answers of a minimum length are eligible