CSS 430
FAQ on Program 1: System Calls and Shell
man fork man close man dup2 man 2 waitSince come commands and system calls have an identical name, you sometimes have to specify which section of manual you would like to see. For instance, if you type man wait, you will get the manual page for the wait command. Type man 2 wait to see the manual page for the waitsystem call. In general, the section 2 gives explanations about system calls.
apropos process
g++ processes.cpp -o processes
PATH=$PATH:/usr/java/j2sdk1.4.1_02/bin/:. export PATH
NAME fork - create a child process SYNOPSIS #include <sys/types.h> #include <unistd.h> pid_t fork(void);This means that you have to include "sys/type.h" and "unistd.h" in order to use the fork system call.
cout << getpid( ) << ": executed this portion" << endl;You might also want to try to use gdb, but I wonder if it is useful in our situation where we handle multiple processes.
a2ps -Puw1-320-p1 processes.cpp a2ps -Puw1-320-p1 Shell.javaIf you want to print out a postscript file, you should use lpr:
lpr -Puw1-320-p1 report.ps
Also, please be reminded:
In Java, the assignment statement for objects means that the left
hand side object reference just receives the reference of the right
hand side object, and thus both left and right hand side references
point to the same object. There occurs no object duplication.
This also applies to the array.
If you want to make a copy of array, use
System.arraycopy( Object src, int src_position, Object dst, int dst_position, int length );Some system-provided classes such as String has a copy constructor. Use them:
String a; a = "abc"; String b( a );
goodall02% cp ~css430/ThreadOS/* ~/ThreadOS cp: /rc44/d03/css430/ThreadOS/Cache.java: Permission denied cp: /rc44/d03/css430/ThreadOS/Directory.java: Permission denied cp: /rc44/d03/css430/ThreadOS/FileDescriptor.java: Permission denied cp: /rc44/d03/css430/ThreadOS/FileSystem.java: Permission denied cp: /rc44/d03/css430/ThreadOS/FileTable.java: Permission denied cp: /rc44/d03/css430/ThreadOS/Inode.java: Permission denied cp: /rc44/d03/css430/ThreadOS/Kernel_org.java: Permission denied cp: /rc44/d03/css430/ThreadOS/QueueNode.java: Permission denied cp: /rc44/d03/css430/ThreadOS/Scheduler.java: Permission denied cp: /rc44/d03/css430/ThreadOS/Scheduler_mul.java: Permission denied cp: /rc44/d03/css430/ThreadOS/Scheduler_pri.java: Permission denied cp: /rc44/d03/css430/ThreadOS/Scheduler_sus.java: Permission denied cp: /rc44/d03/css430/ThreadOS/Shell.java: Permission denied cp: /rc44/d03/css430/ThreadOS/SyncQueue.java: Permission denied
goodall03 javac Shell.java goodall03 java Shell Exception in thread "main" java.lang.NoSuchMethodError: main
mead% javac Shell.java mead% java Boot threadOS ver 1.0: Type ? for help threadOS: a new thread (thread=Thread[Thread-3,2,main] tid=0 pid=-1) --> l Shell l Shell threadOS: a new thread (thread=Thread[Thread-6,2,main] tid=1 pid=0) Shell[1]%
-->l PingPong abc l PingPong java.lang.InstantiationException: PingPong PingPong failed in loading -->
-->l PingPong abc 10000000 l PingPong threadOS: a new thread (thread=Thread[Thread-6,2,main] tid=1 pid=0) abc abc abc abc abc abc ...... ... -->
java.lang.NullPointerException at Kernel.interrupt(Kernel.java:141) at SysLib.cin(SysLib.java:35) at Shell.run(Shell.java:13) at java.lang.Thread.run(Thread.java:498)
shell[0]% TestProg1 & TestProg2 & java.lang.NoSuchMethodException:java.lang.NoSuchMethodException: java.lang.NoSuchMethodException: java.lang.NoSuchMethodException:
StringBuffer sb = new StringBuffer( ); SysLib.cin( sb ); String[] args = SysLib.stringToArgs( sb.toString( ) );
if (args[0] == "exit")This always returns false.
if (args[0].equal( "exit" ) )