Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

UNIX shell programming hellp

Status
Not open for further replies.

Tozilla

Programmer
Mar 28, 2003
3
AU
I'm trying to write a problem which can display a prompt,e.g My_shell$ and accept a command entered by the user by using fgets. Also, it needs to execute the command by invoking fork() and execvp() system call. Then, if user type "logout", the shell should exit.

My problem is that I don't know how to combine fgets, fork() and execvp() together inside the program.
Can anyone please show me some examples?
Thank you
 
Read a command using fgets.
Fork the process, then have the child process exec the command entered.
Repeat.

Look at the man pages for fork and exec (and fgets, if necessary). There should also be some FAQs in either this forum or C++: Unix forum.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top