Changeset 446 for trunk/user/ksh
- Timestamp:
- Jun 19, 2018, 5:12:57 PM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/user/ksh/ksh.c
r445 r446 4 4 // Author : Alain Greiner 5 5 /////////////////////////////////////////////////////////////////////////////// 6 // This single thread application implement a simple shell for ALMOS-MKH. 6 // This applications implement a minimal shell for ALMOS-MKH. 7 // This user process contains two POSIX threads: 8 // - the "main" thread contains the infinite loop implementing 9 // the children processes termination monitoring (children processes 10 // are created by the <load> command and attached to the KSH TXT terminal). 11 // - the "interactive" thread contains the infinite loop implementing 12 // the command interpreter attached to the TXT terminal. 7 13 /////////////////////////////////////////////////////////////////////////////// 8 14 … … 53 59 unsigned int ptr; // read pointer in log_entries[] 54 60 61 pthread_attr_t attr; // monitor thread attributes 62 55 63 //////////////////////////////////////////////////////////////////////////////// 56 64 // Shell Commands … … 100 108 } 101 109 102 // set terminating '0' XXX110 // set terminating '0' 103 111 buf[size-1] = 0; 104 112 … … 449 457 else // it is the parent KSH : ret_fork is the new process PID 450 458 { 451 // give back terminal ownership to KSH if new process created in background /452 // w ait new process completion before returning to command interpreter otherwise459 // give back terminal ownership to KSH 460 // when new process created in background 453 461 if( background ) fg( ksh_pid ); 454 else wait( &status );455 462 456 463 // return to command interpreter … … 715 722 } 716 723 } 717 } 718 719 ///////////////////////// //////////720 int main( int argc , char *argv[])724 } // end parse() 725 726 ///////////////////////// 727 static void interactive() 721 728 { 722 729 char c; // read character 723 730 char buf[CMD_MAX_SIZE]; // buffer for one command 724 unsigned int count = 0;// pointer in buf731 unsigned int count; // pointer in buf 725 732 unsigned int i; // index for loops 726 733 … … 732 739 }; 733 740 734 // log buffer initialisation 735 memset( &log_entries , 0, sizeof(log_entries)); 736 ptw = 0; 737 ptr = 0; 738 739 printf( "\n\n~~~ shell ~~~\n\n" ); 740 741 // command buffer initialisation 741 // initialize command buffer 742 742 memset( buf, 0x20 , sizeof(buf) ); 743 743 count = 0; … … 760 760 761 761 // @@@ 762 // parse("load /bin/user/hello.elf");762 parse("load /bin/user/idbg.elf"); 763 763 // @@@ 764 764 … … 814 814 state = ESCAPE; 815 815 } 816 else if (c == 0x03) // ^C => cancel current command817 {818 for (i = 0; i < count; i++) printf("\b \b");819 for (i = 0; i < sizeof(buf); i++) buf[i] = 0x20;820 count = 0;821 }822 816 else // register character in command buffer 823 817 { … … 910 904 } 911 905 } 906 } // end interactive() 907 908 /////////////////////////////////// 909 int main( int argc , char *argv[] ) 910 { 911 unsigned int cxy; // owner cluster identifier for this KSH process 912 unsigned int lid; // core identifier for this KSH main thread 913 int status; // child process termination status 914 int pid; // chils process identifier 915 pthread_t trdid; // kernel allocated index for interactive thread 916 917 // initialize log buffer 918 memset( &log_entries , 0, sizeof(log_entries)); 919 ptw = 0; 920 ptr = 0; 921 922 get_core( &cxy , & lid ); 923 printf( "\n\n~~~ KSH on core[%x,%d] ~~~\n\n", cxy , lid ); 924 925 // initialize interactive thread attributes 926 attr.attributes = PT_ATTR_DETACH | PT_ATTR_CLUSTER_DEFINED; 927 attr.cxy = cxy; 928 929 // lauch the interactive thread 930 pthread_create( &trdid, 931 &attr, 932 &interactive, // entry function 933 NULL ); 934 935 // enter infinite loop monitoring children processes termination 936 while( 1 ) 937 { 938 pid = wait( &status ); 939 940 #if 0 941 if ( WIFEXITED (status) ) printf("\n[KSH] process %x exited\n" , pid ); 942 else if( WIFSIGNALED(status) ) printf("\n[KSH] process %x killed\n" , pid ); 943 else if( WIFSTOPPED (status) ) printf("\n[KSH] process %x stopped\n", pid ); 944 else printf("\n[KSH] process %x strange\n", pid ); 945 #endif 946 947 } 912 948 } // end main() 913 949 950
Note: See TracChangeset
for help on using the changeset viewer.