1

だから私はプログラミングの割り当てをしようとしています、ここにあります:

Write a C/C++ program (call it string invert) that takes a
string argument from the command line and outputs the string in reversed order. Here comes
the twist: Each process can output at most one character. If you want to output more than a
single character, you must fork off one or more processes in order to do that, and each of the
forked processes in turn outputs a single character. After the call to program string invert
with the command line argument, the output should appear, and no more processes should
be running, in addition to the shell. Test your program on any UNIX/LINUX machine, and
turn in the source code as part of the written assignment. (The source code should be at
most a few lines long.)

文字列の読み取りと反転を簡単に行うことができます。問題ありません。問題は、「各プロセスが最大1文字を出力できる」とはどういう意味かということです。それが何を意味するのかさえ分かりません。コードは必要ありません。理解できれば、自分でコードを実行できると確信しています。それが何を意味するのかを説明してくれる人が必要です。

4

2 に答える 2

2

入力「abcd」があるとすると、プログラムは各文字のプロセスを生成する必要があります。したがって、最初のプロセスは「d」を返し、2番目のプロセスは「c」を返します。割り当ては、おそらく同期プロセスをどれだけよく理解しているかのテストです。

于 2012-09-17T06:26:14.793 に答える
1

すべてのプロセスは、1文字を印刷する必要があります。例:

$yourProgamm sample

通常、サンプル文字列をループして、toなどを呼び出して各文字を出力しますcout。ただし、プロセスごとに1文字しか印刷しないことになっています。あなたが出力することを意味しますe、すべてが大丈夫です。ただし、ループを再度実行しlて同じプロセスを出力すると、2番目の文字が出力されます。

したがって、文字のプロセスをフォークし、そのプロセスにその1文字を印刷させて、ループを続行する必要があります。ランダムな順序の出力が得られる可能性がある他の方法と同期してください(これが割り当ての主なポイントだと思います。意味を確認するために、それなしで数回実行するだけです)。join

于 2012-09-17T06:24:23.827 に答える