LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 05-29-2008, 03:28 AM   #1
youngtrips
LQ Newbie
 
Registered: May 2008
Posts: 2

Rep: Reputation: 0
About the signal after trace the child process


I am working on a project of ACM online judge system.
I use the function ptrace() to trace the program submited.
Now,there are some puzzles.
Here is the code:

void sandbox(char* exec,char* input,char* output,int timelimit,int memlimit)
{
struct rusage usage;
struct rlimit limit;
int wait_val,sig;
pid_t pid;

unsigned long tmp;
unsigned long mem = 0;
double utime,stime;
struct user_regs_struct regs;


pid = fork();
if(pid == -1)
{
printf("fork() error!\n");
}
else if(pid == 0)
{
freopen(input,"r",stdin);
freopen(output,"w",stdout);
limit.rlim_cur = timelimit;
limit.rlim_max = timelimit;
setrlimit(RLIMIT_CPU,&limit);

limit.rlim_cur = memlimit * MEGA_BYTES;
limit.rlim_max = memlimit * MEGA_BYTES;
setrlimit(RLIMIT_AS,&limit);

ptrace(PTRACE_TRACEME, 0, NULL, NULL);
execv(exec,NULL);
}
else
{

wait(&wait_val);
while (wait_val == 1407 )
{

ptrace(PTRACE_GETREGS,pid,NULL,&regs);
if(regs.orig_rax == SYS_write)
{
ptrace(PTRACE_SINGLESTEP, pid, NULL, NULL);
}
else
{
ptrace(PTRACE_SYSCALL,pid,NULL,NULL);
}

tmp = get_curr_mem(pid);
if(mem < tmp)
mem = tmp;
wait(&wait_val);
}
printf("wait_val:%d\n",wait_val);
ptrace(PTRACE_DETACH,pid,(char *)1,0);
getrusage(RUSAGE_CHILDREN,&usage);

}


}

utime = usage.ru_utime.tv_sec * 1000.0 + usage.ru_utime.tv_usec / 1000.0;
stime = usage.ru_stime.tv_sec * 1000.0 + usage.ru_stime.tv_usec / 1000.0;
printf("The total run mem:%ld\n",mem);
printf("user time:%0.0lf\n",utime);
printf("sys time:%0.0lf\n",stime);
printf("Run Time:%0.0lf\n",utime + stime);

}




when use the wait() ,sometimes it may get a siganl greater than 63,such as 2175.
Why it have happend?
Can anyone help me?
Thank you.
 
Old 05-29-2008, 04:57 AM   #2
ophirg
Member
 
Registered: Jan 2008
Location: Israel
Distribution: Kubuntu 13.10
Posts: 134

Rep: Reputation: 34
I think you should use the status from wait with WEXITSTATUS, WIFSIGNALED, WTERMSIG, ...
It may be the problem.
Read about the in "man 2 wait"
 
Old 05-29-2008, 09:44 AM   #3
youngtrips
LQ Newbie
 
Registered: May 2008
Posts: 2

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by ophirg View Post
I think you should use the status from wait with WEXITSTATUS, WIFSIGNALED, WTERMSIG, ...
It may be the problem.
Read about the in "man 2 wait"
Thank you very much.
I have got it.I use WIFSTOPPED and WSTOPSIG.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
how a father process know which child process send the signal SIGCHLD icoming Programming 10 07-20-2010 07:26 AM
How to kill a Child and all its subsequent child process in C shayer009 Programming 3 12-04-2007 12:40 AM
Sending signal to child process DiAvOl Programming 6 05-16-2006 12:16 PM
Killing a child process from another child marri Programming 6 10-01-2004 07:08 PM
child process -1 exited due to signal 6 ashfaq Linux - Software 1 04-09-2004 05:42 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 10:03 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration