Click here to Skip to main content
11,920,377 members (57,949 online)
Rate this:
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.

Posted 1-Oct-12 21:38pm

1 solution

Rate this: bad
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.
mimi from Unknown 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!!!!


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

  Print Answers RSS
0 OriginalGriff 415
1 phil.o 170
2 Dave Kreskowiak 155
4 F-ES Sitecore 130
0 OriginalGriff 6,778
1 KrunalRohit 4,495
2 Sergey Alexandrovich Kryukov 3,203
3 George Jonsson 2,805
4 Suvendu Shekhar Giri 2,181

Advertise | Privacy | Mobile
Web02 | 2.8.151120.1 | Last Updated 2 Oct 2012
Copyright © CodeProject, 1999-2015
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