# Process::Status#to\_s

**URL:** <https://www.ruby-forum.com/t/process-status-to-s/117165>\
**Category:** Development\
**Created:** [October 14, 2007, 4:42am UTC](https://www.ruby-forum.com/t/process-status-to-s/117165 "2007-10-14T04:42:29Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Tanaka\_A](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/c67d28/32.png) [@Tanaka\_A](https://www.ruby-forum.com/u/Tanaka_A)\
**Post date:** [October 14, 2007, 4:42am UTC](https://www.ruby-forum.com/t/process-status-to-s/117165/1 "2007-10-14T04:42:29Z")

</div>

e$B8=:\_e(B Process::Status#to\_s e$B$O@0?t$JJ8;zNs$rJV$7$^$9!#e(B

% ./ruby -e ‘system(“exit 1;”); p $?.to\_s’  
“256”

e$B$3$l$O$o$+$j$K$/$$$N$G0J2\<$N$h$&$JJ8;zNs$rJV$9$N$O$I$&$G$7$ge(B  
e$B$&$+!#e(B

% ./ruby -e ‘system(“exit 1;”); p $?.to\_s’  
“pid 21978 exit 1”

signal e$B$G;`$s$@\>l9ge(B:  
% ./ruby -e ‘system(“kill -ILL $$”); puts $?’  
pid 7666 SIGILL (signal 4) (core dumped)

signal e$B$G;\_$^$C$?\>l9ge(B:  
% ./ruby -e ‘pid = spawn(“kill -TSTP $$”); Process.waitpid pid,  
Process::WUNTRACED; puts $?’  
pid 22014 stopped SIGTSTP (signal 20)

e$B$J$_!"%a%C%;!\<%8$N@8@.%3!\<%I$Oe(B inspect e$B$H6&M-$7$F$_$j!"e(B  
inspect e$B$N7k2L$b\>e5-$N7A\<0$re(B #\<Process::Status: …\> e$B$G3g$Ce(B  
e$B$?$b$N$K$J$j$^$9!#e(B

% ./ruby -e ‘system(“true”); p $?’  
#\<Process::Status: pid 7695 exit 0\>

# Index: process.c

— process.c (e$B%j%S%8%g%se(B 13695)  
+++ process.c (e$B:n6H%3%T!\<e(B)  
@@ -248,20 +248,6 @@

/\*

- call-seq:

- 
  - 

```
stat.to_s => string

```

- 
  - 

- 
  - Equivalent to _stat_`.to_i.to_s`.

- \*/
- 

-static VALUE  
-pst\_to\_s(VALUE st)  
-{

- return rb\_fix2str(pst\_to\_i(st), 10);  
-}
- 
- 

-/\*

- 
  - call-seq:
  - 

```
stat.pid => fixnum

```

  - 
  - Returns the process ID that this status object represents.  
@@ -277,34 +263,20 @@  
return rb\_iv\_get(st, “pid”);  
}

- 

-/\*

- 
  - call-seq:

- 
  - 

```
stat.inspect => string

```

- 
  - 

- 
  - Override the inspection method.

- \*/
- 

-static VALUE  
-pst\_inspect(VALUE st)  
+static void  
+pst\_message(VALUE str, rb\_pid\_t pid, int status)  
{

- VALUE pid;
- int status;
- VALUE str;  
char buf[256];
- 
- pid = pst\_pid(st);
- status = NUM2INT(st);
- 
- str = rb\_sprintf("#\<%s: pid=%ld", rb\_class2name(CLASS\_OF(st)),  
NUM2LONG(pid));

- snprintf(buf, sizeof(buf), “pid %ld”, (long)pid);
- rb\_str\_cat2(str, buf);  
if (WIFSTOPPED(status)) {  
int stopsig = WSTOPSIG(status);  
const char \*signame = ruby\_signal\_name(stopsig);  
if (signame) {

- 

```
 snprintf(buf, sizeof(buf), ",stopped(SIG%s=%d)", signame, 

```

stopsig);

- 

```
 snprintf(buf, sizeof(buf), " stopped SIG%s (signal %d)", signame, 

```

stopsig);  
}  
else {

- 

```
 snprintf(buf, sizeof(buf), ",stopped(%d)", stopsig);

```

- 

```
 snprintf(buf, sizeof(buf), " stopped signal %d", stopsig);

```

}  
rb\_str\_cat2(str, buf);  
}  
@@ -312,22 +284,67 @@  
int termsig = WTERMSIG(status);  
const char \*signame = ruby\_signal\_name(termsig);  
if (signame) {

- 

```
 snprintf(buf, sizeof(buf), ",signaled(SIG%s=%d)", signame, 

```

termsig);

- 

```
 snprintf(buf, sizeof(buf), " SIG%s (signal %d)", signame, 

```

termsig);  
}  
else {

- 

```
 snprintf(buf, sizeof(buf), ",signaled(%d)", termsig);

```

- 

```
 snprintf(buf, sizeof(buf), " signal %d", termsig);

```

}  
rb\_str\_cat2(str, buf);  
}  
if (WIFEXITED(status)) {

- snprintf(buf, sizeof(buf), “,exited(%d)”, WEXITSTATUS(status));

- snprintf(buf, sizeof(buf), " exit %d", WEXITSTATUS(status));  
rb\_str\_cat2(str, buf);  
}  
#ifdef WCOREDUMP  
if (WCOREDUMP(status)) {

- rb\_str\_cat2(str, “,coredumped”);

- rb\_str\_cat2(str, " (core dumped)");  
}  
#endif  
+}
- 
- 

+/\*

- 
  - call-seq:

- 
  - 

```
stat.to_s => string

```

- 
  - 

- 
  - Show pid and exit status as a string.

- \*/
- 

+static VALUE  
+pst\_to\_s(VALUE st)  
+{

- rb\_pid\_t pid;
- int status;
- VALUE str;
- 
- pid = NUM2LONG(pst\_pid(st));
- status = NUM2INT(st);
- 
- str = rb\_str\_buf\_new(0);
- pst\_message(str, pid, status);
- return str;  
+}
- 
- 

+/\*

- 
  - call-seq:

- 
  - 

```
stat.inspect => string

```

- 
  - 

- 
  - Override the inspection method.

- \*/
- 

+static VALUE  
+pst\_inspect(VALUE st)  
+{

- rb\_pid\_t pid;
- int status;
- VALUE str;
- 
- pid = NUM2LONG(pst\_pid(st));
- status = NUM2INT(st);
- 
- str = rb\_sprintf("#\<%s: ", rb\_class2name(CLASS\_OF(st)));
- pst\_message(str, pid, status);  
rb\_str\_cat2(str, “\>”);  
return str;  
}

---

<div class="post-metadata">

**Author:** ![Tanaka\_A](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/c67d28/32.png) [@Tanaka\_A](https://www.ruby-forum.com/u/Tanaka_A)\
**Post date:** [October 15, 2007, 2:46am UTC](https://www.ruby-forum.com/t/process-status-to-s/117165/2 "2007-10-15T02:46:46Z")

</div>

e$B$^$D$b$He(B e$B$f$-$R$m$G$9e(B

In message “Re: [ruby-dev:32053] Process::Status#to\_s”  
on Sun, 14 Oct 2007 11:42:08 +0900, Tanaka A. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
writes:

|e$B8=:\_e(B Process::Status#to\_s e$B$O@0?t$JJ8;zNs$rJV$7$^$9!#e(B  
|  
|% ./ruby -e ‘system(“exit 1;”); p $?.to\_s’  
|“256”  
|  
|e$B$3$l$O$o$+$j$K$/$$$N$G0J2\<$N$h$&$JJ8;zNs$rJV$9$N$O$I$&$G$7$ge(B  
|e$B$&$+!#e(B

e$B%3%\_%C%H$7$F$/$@$5$$!#e(B
