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 |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
 |
GNU/Linux Basic Guide
This 255-page guide will provide you with the keys to understand the philosophy of free software, teach you how to use and handle it, and give you the tools required to move easily in the world of GNU/Linux. Many users and administrators will be taking their first steps with this GNU/Linux Basic guide and it will show you how to approach and solve the problems you encounter.
Click Here to receive this Complete Guide absolutely free. |
|
 |
01-30-2011, 08:56 AM
|
#1
|
|
LQ Newbie
Registered: Feb 2009
Posts: 13
Rep:
|
how to extract output ulimit under popen
A strange question, I guess.
I'm running processes called from a c main program. The calling is performed (for now) as:
FILE * res=popen(ulimit -t 1; prg args);
So I can read the stdout of the process as a file and analyze it. The time limit is important for me.
2 questions:
1. How do I get to know if the process terminated on its own or by the ulimit?
2. How do I limit to times that are less than 1 sec (I have many of those).
I know that setrlimit exists, just before I change my whole approach I wanted to see if I can deal with these things from the outside.
Thanks!
|
|
|
|
01-31-2011, 03:20 PM
|
#2
|
|
Senior Member
Registered: Sep 2004
Distribution: FreeBSD 9.1, Kubuntu 12.10
Posts: 2,962
Rep: 
|
If the process exceeds its CPU time limit, the kernel will end the process with SIGXCPU if the soft (but not hard) limit is reached, otherwise with SIGKILL. If you want to obtain the exit status, you'll need the process ID or process group to use with waitpid, which means the monitoring process needs to be the parent of the monitored process. That means you can't use popen. You'll probably have to do it manually with pipe, fork, dup2, setrlimit, and execvp. Using system instead of execvp might just give you the exit status of the shell; I'm not sure if it passes on the signal.
You cannot specify a non-integer time limit, even with setrlimit.
I'm not sure of a real use for limiting CPU time, other than debugging when you're having a problem with a race condition. What exactly are you using it for? Do you handle SIGXCPU?
Kevin Barry
Last edited by ta0kira; 01-31-2011 at 03:31 PM.
|
|
|
|
02-22-2011, 01:36 PM
|
#3
|
|
LQ Newbie
Registered: Feb 2009
Posts: 13
Original Poster
Rep:
|
Hi Kevin,
Thanks for the answer. I'm still having issues with these things. Sorry for taking so much time to respond (this is a late-night hobby I'm developing, with no extensive background).
First, it's probably best to explain what I try to do.
basically, I have a (main) program that "creates" c-codes, compiles them, runs them with inputs and reads the outputs.
I use popen to get the stdout of these and analyze it.
The results are unexpected a-priory, meaning: infinite run-time, infinite stdout, no output at all etc.
I now measure the time from start to end and if it exceeds something like half a second I consider it "infinite", but I still have problems with reading of infinite outputs, and generally - knowing when the sub-process stopped (I want to analyze the data only after all of it is already given, now it's a FILE *).
the system command is good for that, but can't get access to the stdout...
If you have any ideas how this can be done, I would be very grateful!
Thanks again,
Ranny
|
|
|
|
| Thread Tools |
Search this Thread |
|
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT -5. The time now is 10:13 AM.
|
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|