当前位置: 首页 > 工具软件 > PinkTrace > 使用案例 >

linux如何执行rb代码,Ruby 版的 PinkTrace 示例 pink-fork-linux.rb

巫马瀚漠
2023-12-01

#!/usr/bin/env ruby

# coding: utf-8

# vim: set sw=2 sts=2 et fenc=utf-8 :

=begin

An example demonstrating the tracing fork

=end

require 'PinkTrace'

pid = fork do

# Prepare for tracing.

PinkTrace::Trace.me

# Stop to give the parent a chance to resume execution after setting options.

Process.kill 'STOP', Process.pid

puts "hello world"

end

Process.wait # sets $?

event = PinkTrace::Event.decide # uses $?.status by default

unless event == PinkTrace::Event::EVENT_STOP

puts "wtf?"

PinkTrace::Trace.kill pid

exit 1

end

# Set tracing options

PinkTrace::Trace.setup pid

# Let the child resume its execution.

PinkTrace::Trace.resume pid

# Wait for the child to exit.

Process.wait

 类似资料: