How to setitimer for the child process in golang?

155 views
Skip to first unread message

GaoPeng(高朋)

unread,
Jun 30, 2014, 10:00:16 AM6/30/14
to golan...@googlegroups.com
In C , I can use setitimer after fork, and signal SIGALARM Periodically.But In Go I have no idea about how to use syscall setitimer to child process. Is there any way to specify the pid of setitimer after os.StartProcess?

Ian Lance Taylor

unread,
Jun 30, 2014, 11:07:30 AM6/30/14
to GaoPeng(高朋), golang-nuts
What do you really want to do?

Two other ways to approach this, depending on your goals, are
time.NewTicker and the runtime/pprof package.

Ian

GaoPeng(高朋)

unread,
Jun 30, 2014, 8:07:38 PM6/30/14
to golan...@googlegroups.com, gaop...@gmail.com
I want use ptrace to trace a untrusted code to limit it's resource like CPU time , memory and syscall. So I want tracee process signal SIGALARM in order to make tracer stop it and have a check for the resource usage. The methods you give applys for the current process. 

GaoPeng(高朋)

unread,
Jun 30, 2014, 8:23:05 PM6/30/14
to golan...@googlegroups.com, gaop...@gmail.com
http://play.golang.org/p/byg5BrdrEJ 

It's piece of my code , I  want to add below SIGALARM below line 83.


On Monday, June 30, 2014 11:07:30 PM UTC+8, Ian Lance Taylor wrote:

GaoPeng(高朋)

unread,
Jul 1, 2014, 1:00:00 AM7/1/14
to golan...@googlegroups.com
Oh. I got the idea.
Just like:

ticker := time.Newtikcer(dur)
 for _ = range ticker.C{
   proc.Signal(os.SIgnal(syscall.SIGALARM))
}

thx!
Reply all
Reply to author
Forward
0 new messages