[Tutor] python time

Alan Gauld alan.gauld at btinternet.com
Fri Dec 4 23:42:50 CET 2009


Only just spotted this.

"spir" <denis.spir at free.fr> wrote


>> It's not C's function, it's a Unix system call.
>> It's been part of Unix since BSD 4.2
>>
> I am confused here. That's what I first thought (there _must_ be a way to 
> get time
> more precise that seconds!). But on my system (ubuntu 9.10) I cannot find 
> the
> proper manner to use these system calls. Even from the command-line 
> directly.

You cannot call system calls from the command line.
You can only execute Unixc commands from the shell. A command is a
standaline program(executable), it is quite different to a system call.
A system call in Unix is the C API provided by the kernel.
It can only be called by C or some other language that can
link with the kernel libraries - eg Fortran, Assembler etc.

So when you use Python it calls the Unix system call via C.

[Aside: There is an excellent O'Reilly book on using the Unix system calls
from C: "Unix Systems Programming for SVR4" Much of it is directly
applicable to Python - sockets, file handling, time, fork, spawn, etc
It can be bought used for just a few dollars on Amazon...]

> This let me think gettimeofday() and ftime() are C routines,

They are C functions provided by the Unix kernel.
This makes them Unix OS system calls rather than C standard
library functions.

>> time() is the lowest common denominator supported by any ANSI C system.

Whereas time is provided by the C standard libvrary and is not
part of the Unix kernel.

> So, I still have the issue of not beeing smart enough to access one
> of these systems-provided features.

You access them by using Python.

HTH,

-- 
Alan Gauld
Author of the Learn to Program web site
http://www.alan-g.me.uk/ 




More information about the Tutor mailing list