Class: CPUExtension::CPUHogs

Inherits:
Object
  • Object
show all
Defined in:
ext/distem/cpuhogs/cpuhogs.c

Instance Attribute Summary (collapse)

Instance Method Summary (collapse)

Constructor Details

- (Object) initialize



14
15
16
17
18
19
20
21
22
23
# File 'ext/distem/cpuhogs/cpuhogs.c', line 14

static VALUE cpuhogs_init(VALUE self)
{
	rb_iv_set(self, "@pid", INT2NUM(0));
	cmds = ALLOC(cpu_cmds);
	cmds->cpufreq = 1;
	cmds->interval = 10000000;
	cmds->cpus = 0;

	return self;
}

Instance Attribute Details

- (Object) pid (readonly)

Instance Method Details

- (Object) run



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'ext/distem/cpuhogs/cpuhogs.c', line 33

static VALUE cpuhogs_run(VALUE self, VALUE hash)
{
	int pid;

	pid = fork();
	if (pid < 0)
		rb_raise(rb_eRuntimeError,"fork");
	if (!pid)
	{
		if (setsid() < 0)
			rb_raise(rb_eRuntimeError,"setsid");
		close(STDIN_FILENO);
		close(STDOUT_FILENO);
		close(STDERR_FILENO);

		cmds->ratios = ALLOC_N(cpu_ratio,MAX_CPUS);

		rb_hash_foreach(hash,parse_hash,Qnil);

		run(cmds);
                exit(0);
	}
	else
  {
		rb_iv_set(self, "@pid", INT2NUM(pid));
  }
	return Qnil;
}

- (Boolean) running?

Returns:

  • (Boolean)


73
74
75
76
77
78
79
# File 'ext/distem/cpuhogs/cpuhogs.c', line 73

static VALUE cpuhogs_is_run(VALUE self)
{
	if (NUM2INT(rb_iv_get(self, "@pid")))
		return Qtrue;
	else
		return Qfalse;
}

- (Object) stop



62
63
64
65
66
67
68
69
70
71
# File 'ext/distem/cpuhogs/cpuhogs.c', line 62

static VALUE cpuhogs_stop(VALUE self)
{
	int pid;
	pid = NUM2INT(rb_iv_get(self, "@pid"));
	kill(pid,SIGKILL);
  waitpid(pid,NULL,0);
	rb_iv_set(self, "@pid", INT2NUM(0));

	return Qnil;
}