Tag Info

Hot answers tagged

20

look at the time man page on your system, some implementations have format options to include I/O, CPU and Memory stats (-f). For instance, GNU time, with -v will show all available info (here on Linux): /usr/bin/time -v ls Command being timed: "ls" User time (seconds): 0.00 System time (seconds): 0.00 Percent of CPU this job got: 0% Elapsed (wall ...


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 ...


13

There are DST-free timezone definitions provided which just define the GMT-offset, called Etc/GMT±X: $ date Mon Apr 7 11:08:56 CEST 2014 $ TZ=Etc/GMT-1 date Mon Apr 7 10:09:16 GMT-1 2014 $ Just link/copy the one you need to /etc/localtime and you should be fine and DST-free: $ ln -s /usr/share/zoneinfo/Etc/GMT-1 /etc/localtime Edit: For non-integer ...


12

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

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] ...


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 ...


7

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 ...


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

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


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

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 ...


5

On OS/X or FreeBSD, it's the -U option. Linux now also stores the birth/creation time on most of its native file systems, but there's no API to retrieve it yet. On ext4 filesystems, you can use debugfs to get it though: $ sudo debugfs /dev/some/fs stat /some/file [...] crtime: 0x53208d7a:9045625c -- Wed Mar 12 16:38:18 2014 [...] (where /some/file is the ...


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

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

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 ...


4

Call time myprogram. This reports wall clock time, user time and system time. User time is the time spent by the process in computations. If the program is multithreaded and the machine has multiple processors, the time spent on all processors is summed (so for a sufficiently parallel program, the user time can be more than the wall clock time). The system ...


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

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, ...



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