【问题标题】:how to solve this terminal or code problem如何解决这个终端或代码问题
【发布时间】:2021-08-13 08:30:23
【问题描述】:
#include<stdio.h>
#include<unistd.h>

int main(){
    
    int x;
    pid_t myPID,childPID;
    x=10;
    myPID = getpid();
    childPID=fork();

    printf("%s \n","how are you");
    
    return 0;
}

return ans this format.not print new line.

bobi@bobi-VirtualBox:~/code$ gcc parent_child.c -o parent_child

bobi@bobi-VirtualBox:~/code$ ./parent_child

how are you 

bobi@bobi-VirtualBox:~/code$ how are you 

【问题讨论】:

  • 代码清晰。你对应该发生的事情有什么期望?大概它与发生的事情不符。
  • 你好吗 bobi@bobi-VirtualBox:~/code$ 你好吗这部分显示你好吗,这个格式
  • 请将此格式正确地添加到您的问题中。在 cmets 中没有可用的格式。

标签: c fork


【解决方案1】:

如果我理解正确,您希望孩子在后台运行并在父母返回后在 shell 上打印?试试:

 childPID=fork();
 if (!childPID) {sleep(1);}
 printf("%s \n","how are you");

【讨论】:

    猜你喜欢
    • 2022-11-25
    • 1970-01-01
    • 2021-09-21
    • 1970-01-01
    • 2017-10-03
    • 1970-01-01
    • 1970-01-01
    • 2021-06-28
    • 2020-06-15
    相关资源
    最近更新 更多