Results 1 to 10 of 10
We have a home work in a course called Operating systems.
The user calls a program with some or none input parameters. If the user puts parameter the program initiates ...
- 10-21-2009 #1Just Joined!
- Join Date
- Oct 2009
- Posts
- 7
SOLVED: How to implement a PAGER using C-code?
We have a home work in a course called Operating systems.
The user calls a program with some or none input parameters. If the user puts parameter the program initiates a pipe, which first do grep of the environment variables with the grep parameters, then sort, and then it should use a pager and after that print the environment variables to the shell. In total I have four processes.
I don’t know how I should implement a pager. We should implement LESS or MORE depending on some factors. The total program can be written in 50 rows in C according to the teacher, so by that I understand he don’t mean we shall implement LESS and MORE by ourselves, since that would take a lot more rows of C-code.
So how do I program a program to print to the shell using a pager?
Thanks!
Anders Branderud
proofofaCreator.wordpress.com
- 10-21-2009 #2
This is encroaching a rule violation: http://www.linuxforums.org/forum/lin...ums-rules.html
That being said, I would look at the man pages for system call for executing on the shell in C.
- 10-21-2009 #3Just Joined!
- Join Date
- Oct 2009
- Posts
- 7
Coopstah13,
"This is encroaching a rule violation: ...
That being said, I would look at the man pages for system call for executing on the shell in C."
I am sorry, I didn't know that. That being said I think it is reasonable that I post this question here. I don't want anyone to provide a full solution, I just want a hint. (If the moderator don't agree with me he can close this thread).
I forgot to tell that in this task we are not allowed to do the system-call.
Edit: I know hot to solve the problem now.
Anders Branderud
proofofaCreator.blogspot.com
- 10-21-2009 #4Linux Guru
- Join Date
- Apr 2009
- Location
- I can be found either 40 miles west of Chicago, or in a galaxy far, far away.
- Posts
- 8,974
What do you think the pager is supposed to do? From what you have said, the pager is a means of formatting the output so it can be easily read from the terminal. Honestly, this is a single process job. By printing to the shell, I think your professor means the terminal. So, your first job is to break the work down into a process flow. You can use a flowchart or more simply pseudo-code. Once you have the process and data flow clarified, writing the C code is trivial (relatively).
Sometimes, real fast is almost as good as real time.
Just remember, Semper Gumbi - always be flexible!
- 10-22-2009 #5Just Joined!
- Join Date
- Oct 2009
- Posts
- 7
Thanks!
I had already implemented my own less-pager with minimal functionality.
But I realised yesterday after writing this that the course instructor probably wants us to use execp or the like to do less, grep, sort and printenv.
He said that the minimum code length for all of the program is 50 rows and to implement all those functions with their functionality takes much more code than that.
Have a nice day!
Anders Branderud
proofofaCreator.wordpress.com
- 10-22-2009 #6Linux Guru
- Join Date
- Apr 2009
- Location
- I can be found either 40 miles west of Chicago, or in a galaxy far, far away.
- Posts
- 8,974
The exec... calls like execp() are basically system(), or what system() does under the covers, so you might want to check with your professor to make sure it is ok to do that. Frankly, from what you say you need to do for this assignment, 50-100 lines of code (other than setup stuff like #include's and variable declaractions) should be adequate to do this. Anyway, it sounds like you are getting into the swing of it. Good luck.
Sometimes, real fast is almost as good as real time.
Just remember, Semper Gumbi - always be flexible!
- 10-22-2009 #7Just Joined!
- Join Date
- Oct 2009
- Posts
- 7
How to program execvp to do grep.
Rubberman, Thanks!
Yes, that's what the professor has intended.
I have one more question. I have a process. I run execvp and I command it to do “printenv”. It works fine.
Before I do the execvp-call I pipe STDOUT to go to a specific pipe. After that I restore STDOUT. I read that pipe in another process. I have tested it and it works.
Now in this other process I want to do execvp again and I want to command execvp to do “grep …”.
I don’t succeed in doing this.
Here are some of my code:
char* environment_variables_vector[60];
My function call is this: execvp ("grep", environment_variables_vector)
Environment_variables_vector have this format:
Position 0 is a pointer to the string “grep PATH”
Position 1 is a pointer to: A nulterminated string containing an environment variable
Position 2 is a pointer to: Another nulterminated string containing another environment variable
..etcetera, up to
Position 52 is a pointer to: Another nulterminated string containing another environment variable.
When I run the program it doesn’t run the code after the execvp-call. So my question is how I shall do grep on all these environment variables using the function execvp?
Thanks in advance!
Anders Branderud
proofofaCreator.wordpress.com
- 10-22-2009 #8
- 10-23-2009 #9Just Joined!
- Join Date
- Oct 2009
- Posts
- 7
Rubberman,
Okay!
I solved the problem now this morning. : )
Anders Branderud
proofofaCreator.wordpress.com
- 10-23-2009 #10Linux Guru
- Join Date
- Apr 2009
- Location
- I can be found either 40 miles west of Chicago, or in a galaxy far, far away.
- Posts
- 8,974
Glad to hear it. Usually folks on these forums are willing to help point you in the right direction for school work, but we stop when it seems that you want us to do the work for you. Understandable I think. Anyway, good luck with your classes.
Sometimes, real fast is almost as good as real time.
Just remember, Semper Gumbi - always be flexible!


Reply With Quote
