#include #include #include #include const char *commands[] = { "quit", "who", "ls", "uptime", "emacs", "hostname", "date", "" }; void print_menu( void ) { int i; printf( "Enter" ); for ( i = 0; commands[ i ][ 0 ]; ++i ) printf( " %d=>%s", i, commands[ i ] ); printf( "-> " ); } int main() { int cmd; print_menu(); scanf( "%d", &cmd ); while ( cmd != 0 ) { int pid = fork(); if ( pid == 0 ) { if ( cmd == 1 ) execl( "/usr/bin/who", "who", NULL ); if ( cmd == 2 ) execl( "/bin/ls", "ls", NULL ); if ( cmd == 3 ) execl( "/usr/bin/uptime", "uptime", NULL ); if ( cmd == 4 ) execl( "/usr/bin/emacs", "emacs", NULL ); if ( cmd == 5 ) execl( "/bin/hostname", "uptime", NULL ); if ( cmd == 6 ) execl( "/bin/date", "uptime", NULL ); printf( "command %d not supported\n", cmd ); exit( 1 ); } wait( NULL ); print_menu(); scanf( "%d", &cmd ); } }