| 
									
										
										
										
											1996-08-26 18:22:31 +00:00
										 |  |  | This file is times.def, from which is created times.c. | 
					
						
							|  |  |  | It implements the builtin "times" in Bash. | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | Copyright (C) 1987, 1989, 1991 Free Software Foundation, Inc. | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | This file is part of GNU Bash, the Bourne Again SHell. | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | Bash is free software; you can redistribute it and/or modify it under | 
					
						
							|  |  |  | the terms of the GNU General Public License as published by the Free | 
					
						
							|  |  |  | Software Foundation; either version 1, or (at your option) any later | 
					
						
							|  |  |  | version. | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | Bash is distributed in the hope that it will be useful, but WITHOUT ANY | 
					
						
							|  |  |  | WARRANTY; without even the implied warranty of MERCHANTABILITY or | 
					
						
							|  |  |  | FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License | 
					
						
							|  |  |  | for more details. | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | You should have received a copy of the GNU General Public License along | 
					
						
							|  |  |  | with Bash; see the file COPYING.  If not, write to the Free Software | 
					
						
							|  |  |  | Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | $PRODUCES times.c | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | $BUILTIN times | 
					
						
							|  |  |  | $FUNCTION times_builtin | 
					
						
							|  |  |  | $SHORT_DOC times | 
					
						
							|  |  |  | Print the accumulated user and system times for processes run from | 
					
						
							|  |  |  | the shell. | 
					
						
							|  |  |  | $END | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											1996-12-23 17:02:34 +00:00
										 |  |  | #include <config.h> | 
					
						
							| 
									
										
										
										
											1996-08-26 18:22:31 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											1996-12-23 17:02:34 +00:00
										 |  |  | #if defined (HAVE_UNISTD_H) | 
					
						
							|  |  |  | #  include <unistd.h> | 
					
						
							|  |  |  | #endif | 
					
						
							| 
									
										
										
										
											1996-08-26 18:22:31 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											1996-12-23 17:02:34 +00:00
										 |  |  | #include <stdio.h> | 
					
						
							|  |  |  | #include "../bashtypes.h" | 
					
						
							|  |  |  | #include "../shell.h" | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #if TIME_WITH_SYS_TIME | 
					
						
							| 
									
										
										
										
											1996-08-26 18:22:31 +00:00
										 |  |  | #  include <sys/time.h> | 
					
						
							| 
									
										
										
										
											1996-12-23 17:02:34 +00:00
										 |  |  | #  include <time.h> | 
					
						
							|  |  |  | #else | 
					
						
							|  |  |  | #  if defined (HAVE_SYS_TIME_H) | 
					
						
							|  |  |  | #    include <sys/time.h> | 
					
						
							|  |  |  | #  else | 
					
						
							|  |  |  | #    include <time.h> | 
					
						
							|  |  |  | #  endif | 
					
						
							|  |  |  | #endif | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #if defined (HAVE_SYS_TIMES_H) | 
					
						
							|  |  |  | #  include <sys/times.h> | 
					
						
							|  |  |  | #endif /* HAVE_SYS_TIMES_H */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #if defined (HAVE_SYS_RESOURCE_H) | 
					
						
							| 
									
										
										
										
											1996-08-26 18:22:31 +00:00
										 |  |  | #  include <sys/resource.h> | 
					
						
							| 
									
										
										
										
											1996-12-23 17:02:34 +00:00
										 |  |  | #endif | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include "common.h" | 
					
						
							| 
									
										
										
										
											1996-08-26 18:22:31 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											1996-12-23 17:02:34 +00:00
										 |  |  | /* Print the totals for system and user time used. */ | 
					
						
							|  |  |  | int | 
					
						
							| 
									
										
										
										
											1996-08-26 18:22:31 +00:00
										 |  |  | times_builtin (list) | 
					
						
							|  |  |  |      WORD_LIST *list; | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											1996-12-23 17:02:34 +00:00
										 |  |  | #if defined (HAVE_GETRUSAGE) && defined (HAVE_TIMEVAL) && defined (RUSAGE_SELF) | 
					
						
							| 
									
										
										
										
											1996-08-26 18:22:31 +00:00
										 |  |  |   struct rusage self, kids; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   getrusage (RUSAGE_SELF, &self); | 
					
						
							|  |  |  |   getrusage (RUSAGE_CHILDREN, &kids);	/* terminated child processes */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											1996-12-23 17:02:34 +00:00
										 |  |  |   print_timeval (stdout, &self.ru_utime); | 
					
						
							| 
									
										
										
										
											1996-08-26 18:22:31 +00:00
										 |  |  |   putchar (' '); | 
					
						
							| 
									
										
										
										
											1996-12-23 17:02:34 +00:00
										 |  |  |   print_timeval (stdout, &self.ru_stime); | 
					
						
							| 
									
										
										
										
											1996-08-26 18:22:31 +00:00
										 |  |  |   putchar ('\n'); | 
					
						
							| 
									
										
										
										
											1996-12-23 17:02:34 +00:00
										 |  |  |   print_timeval (stdout, &kids.ru_utime); | 
					
						
							| 
									
										
										
										
											1996-08-26 18:22:31 +00:00
										 |  |  |   putchar (' '); | 
					
						
							| 
									
										
										
										
											1996-12-23 17:02:34 +00:00
										 |  |  |   print_timeval (stdout, &kids.ru_stime); | 
					
						
							| 
									
										
										
										
											1996-08-26 18:22:31 +00:00
										 |  |  |   putchar ('\n'); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											1996-12-23 17:02:34 +00:00
										 |  |  | #else | 
					
						
							|  |  |  | #  if defined (HAVE_TIMES) | 
					
						
							| 
									
										
										
										
											1996-08-26 18:22:31 +00:00
										 |  |  |   /* As of System V.3, HP-UX 6.5, and other ATT-like systems, this stuff is | 
					
						
							|  |  |  |      returned in terms of clock ticks (HZ from sys/param.h).  C'mon, guys. | 
					
						
							|  |  |  |      This kind of stupid clock-dependent stuff is exactly the reason 4.2BSD | 
					
						
							|  |  |  |      introduced the `timeval' struct. */ | 
					
						
							| 
									
										
										
										
											1996-12-23 17:02:34 +00:00
										 |  |  |   struct tms t; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   times (&t); | 
					
						
							| 
									
										
										
										
											1996-08-26 18:22:31 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											1996-12-23 17:02:34 +00:00
										 |  |  |   print_time_in_hz (stdout, t.tms_utime); | 
					
						
							| 
									
										
										
										
											1996-08-26 18:22:31 +00:00
										 |  |  |   putchar (' '); | 
					
						
							| 
									
										
										
										
											1996-12-23 17:02:34 +00:00
										 |  |  |   print_time_in_hz (stdout, t.tms_stime); | 
					
						
							| 
									
										
										
										
											1996-08-26 18:22:31 +00:00
										 |  |  |   putchar ('\n'); | 
					
						
							| 
									
										
										
										
											1996-12-23 17:02:34 +00:00
										 |  |  |   print_time_in_hz (stdout, t.tms_cutime); | 
					
						
							| 
									
										
										
										
											1996-08-26 18:22:31 +00:00
										 |  |  |   putchar (' '); | 
					
						
							| 
									
										
										
										
											1996-12-23 17:02:34 +00:00
										 |  |  |   print_time_in_hz (stdout, t.tms_cstime); | 
					
						
							| 
									
										
										
										
											1996-08-26 18:22:31 +00:00
										 |  |  |   putchar ('\n'); | 
					
						
							| 
									
										
										
										
											1996-12-23 17:02:34 +00:00
										 |  |  | #  else /* !HAVE_TIMES */ | 
					
						
							|  |  |  |   printf ("0.00 0.00\n0.00 0.00\n"); | 
					
						
							|  |  |  | #  endif /* HAVE_TIMES */ | 
					
						
							|  |  |  | #endif /* !HAVE_TIMES */ | 
					
						
							| 
									
										
										
										
											1996-08-26 18:22:31 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |   return (EXECUTION_SUCCESS); | 
					
						
							|  |  |  | } |