Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: Linux
i have the following assignment but i have no idea where to start.pls help at least tell me what kind of material i sld read.
 
write a program doit that takes another command as an argument and executes that command. For instance, executing:
% doit cat /etc/motd
would invoke the cat command on the file /etc/motd, which will print the current “message of the day.” After execution of the specified command has completed, doit should display statistics that show some of the system resources the command used.
 
mimi
Posted 1-Oct-12 21:38pm

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

The first point is almost trivial: your program's main function (assuming you are using C), namely:
int main(int argc, char* argv[])
receives the command to execute (e.g. "cat") as arg[1] and its parameters as arg[2], arg[3], etc... A very simple implementation would use the system[^] call to execute the command.
 

The second point might be implemented, I guess, accessing the /proc/<pid>/stat[^] file.
  Permalink  
Comments
mimi from Unknown at 2-Oct-12 3:50am
   
yeah tnx for ur replay but i am a beginner to this and i am having a hard time tring to understand what u meant.
I was reading a bash scripting books to help me with this assignment.I kinda felt like i am not getting closer to the solution so ...... what sld i read to understand this...pls help!!!!

mimi

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Kornfeld Eliyahu Peter 275
1 Maciej Los 204
2 Sergey Alexandrovich Kryukov 200
3 King Fisher 185
4 OriginalGriff 183
0 OriginalGriff 6,223
1 DamithSL 4,724
2 Maciej Los 4,196
3 Kornfeld Eliyahu Peter 3,894
4 Sergey Alexandrovich Kryukov 3,496


Advertise | Privacy | Mobile
Web01 | 2.8.141220.1 | Last Updated 2 Oct 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100