c++ - 过程控制

标签 c++ c unix fork

所以我正在尝试做我的编程作业,这里是:

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.)

我可以轻松读取和反转字符串,没问题。问题是“每个进程最多只能输出一个字符”是什么意思。我什至不明白那是什么意思。我不需要任何代码,我相信一旦我理解了我就可以自己做。我只需要有人来解释那是什么意思。

最佳答案

假设您有输入“abcd”,那么您的程序应该为每个字符生成一个进程。所以第一个进程将返回“d”,第二个进程将返回“c”,依此类推。该作业可能会测试您对同步进程的理解程度。

关于c++ - 过程控制,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12453994/

相关文章:

php - 如何使用 php 在 Windows 命令提示符下编译 C 代码

java - 如何使用Android接收特定 radio 频率

复制程序: File Permission Denied

linux - 仅当连字符后面的数字超过 2 位时才删除数字之间的连字符

c - 未决请求队列存储在哪里?

c++ - 将字符串作为二进制写入/读取到随机访问的文件中

c++ - 如何使用 OpenGL 绘制 OpenMesh

c++ - 声明没有默认构造函数或复制构造函数的成员变量

c++ - 如何正确定义功能并实现它们?

c - ragel如何从文件中读取源代码?