summaryrefslogtreecommitdiff
path: root/process.c
diff options
context:
space:
mode:
authormatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2001-02-16 07:53:21 +0000
committermatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2001-02-16 07:53:21 +0000
commite1c29a3f13a8d5ca0f9a4e491a752c73aca1d721 (patch)
tree6aa26039a5949f42bd879914ef2f124c5144a392 /process.c
parent9ac8f70f3da942e8a1bc6cadc87cbeaaec2bf44f (diff)
* io.c (set_outfile): f should be the FILE* from the assigning value.
* ext/socket/socket.c (tcp_s_open): should not give default value to local_host. * time.c (time_s_times): move to Process::times. * file.c (rb_file_s_lchmod): new method File::lchmod. * file.c (rb_file_s_lchown): new method File::lchown. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@1192 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'process.c')
-rw-r--r--process.c77
1 files changed, 63 insertions, 14 deletions
diff --git a/process.c b/process.c
index f49ef23eae..dcde77a9bb 100644
--- a/process.c
+++ b/process.c
@@ -49,6 +49,14 @@ struct timeval rb_time_interval _((VALUE));
#undef HAVE_GETPGRP
#endif
+#ifdef HAVE_SYS_TIMES_H
+#include <sys/times.h>
+#endif
+
+#if defined(HAVE_TIMES) || defined(NT)
+static VALUE S_Tms;
+#endif
+
static VALUE
get_pid()
{
@@ -108,7 +116,16 @@ pst_bitand(st1, st2)
}
static VALUE
-pst_ifstopped(st)
+pst_rshift(st1, st2)
+ VALUE st1, st2;
+{
+ int status = NUM2INT(st1) >> NUM2INT(st2);
+
+ return INT2NUM(status);
+}
+
+static VALUE
+pst_wifstopped(st)
VALUE st;
{
int status = NUM2INT(st);
@@ -120,7 +137,7 @@ pst_ifstopped(st)
}
static VALUE
-pst_stopsig(st)
+pst_wstopsig(st)
VALUE st;
{
int status = NUM2INT(st);
@@ -129,7 +146,7 @@ pst_stopsig(st)
}
static VALUE
-pst_ifsignaled(st)
+pst_wifsignaled(st)
VALUE st;
{
int status = NUM2INT(st);
@@ -141,7 +158,7 @@ pst_ifsignaled(st)
}
static VALUE
-pst_termsig(st)
+pst_wtermsig(st)
VALUE st;
{
int status = NUM2INT(st);
@@ -150,7 +167,7 @@ pst_termsig(st)
}
static VALUE
-pst_ifexited(st)
+pst_wifexited(st)
VALUE st;
{
int status = NUM2INT(st);
@@ -162,7 +179,7 @@ pst_ifexited(st)
}
static VALUE
-pst_exitstatus(st)
+pst_wexitstatus(st)
VALUE st;
{
int status = NUM2INT(st);
@@ -171,7 +188,7 @@ pst_exitstatus(st)
}
static VALUE
-pst_coredump(st)
+pst_wcoredump(st)
VALUE st;
{
#ifdef WCOREDUMP
@@ -1254,6 +1271,31 @@ proc_setegid(obj, egid)
return egid;
}
+VALUE
+rb_proc_times(obj)
+ VALUE obj;
+{
+#if defined(HAVE_TIMES) && !defined(__CHECKER__)
+#ifndef HZ
+# ifdef CLK_TCK
+# define HZ CLK_TCK
+# else
+# define HZ 60
+# endif
+#endif /* HZ */
+ struct tms buf;
+
+ if (times(&buf) == -1) rb_sys_fail(0);
+ return rb_struct_new(S_Tms,
+ rb_float_new((double)buf.tms_utime / HZ),
+ rb_float_new((double)buf.tms_stime / HZ),
+ rb_float_new((double)buf.tms_cutime / HZ),
+ rb_float_new((double)buf.tms_cstime / HZ));
+#else
+ rb_notimplement();
+#endif
+}
+
VALUE rb_mProcess;
void
@@ -1297,18 +1339,19 @@ Init_process()
rb_define_method(rb_cProcStatus, "==", pst_equal, 1);
rb_define_method(rb_cProcStatus, "&", pst_bitand, 1);
+ rb_define_method(rb_cProcStatus, ">>", pst_rshift, 1);
rb_define_method(rb_cProcStatus, "to_i", pst_to_i, 0);
rb_define_method(rb_cProcStatus, "to_int", pst_to_i, 0);
rb_define_method(rb_cProcStatus, "to_s", pst_to_s, 0);
rb_define_method(rb_cProcStatus, "inspect", pst_to_s, 0);
- rb_define_method(rb_cProcStatus, "ifstopped?", pst_ifstopped, 0);
- rb_define_method(rb_cProcStatus, "stopsig", pst_stopsig, 0);
- rb_define_method(rb_cProcStatus, "ifsignaled?", pst_ifsignaled, 0);
- rb_define_method(rb_cProcStatus, "termsig", pst_termsig, 0);
- rb_define_method(rb_cProcStatus, "ifexited?", pst_ifexited, 0);
- rb_define_method(rb_cProcStatus, "exitstatus", pst_exitstatus, 0);
- rb_define_method(rb_cProcStatus, "coredump?", pst_coredump, 0);
+ rb_define_method(rb_cProcStatus, "stopped?", pst_wifstopped, 0);
+ rb_define_method(rb_cProcStatus, "stopsig", pst_wstopsig, 0);
+ rb_define_method(rb_cProcStatus, "signaled?", pst_wifsignaled, 0);
+ rb_define_method(rb_cProcStatus, "termsig", pst_wtermsig, 0);
+ rb_define_method(rb_cProcStatus, "exited?", pst_wifexited, 0);
+ rb_define_method(rb_cProcStatus, "exitstatus", pst_wexitstatus, 0);
+ rb_define_method(rb_cProcStatus, "coredump?", pst_wcoredump, 0);
rb_define_module_function(rb_mProcess, "pid", get_pid, 0);
rb_define_module_function(rb_mProcess, "ppid", get_ppid, 0);
@@ -1338,4 +1381,10 @@ Init_process()
rb_define_module_function(rb_mProcess, "euid=", proc_seteuid, 1);
rb_define_module_function(rb_mProcess, "egid", proc_getegid, 0);
rb_define_module_function(rb_mProcess, "egid=", proc_setegid, 1);
+
+ rb_define_module_function(rb_mProcess, "times", rb_proc_times, 0);
+
+#if defined(HAVE_TIMES) || defined(NT)
+ S_Tms = rb_struct_define("Tms", "utime", "stime", "cutime", "cstime", 0);
+#endif
}