[linux操作系统实验]进程的创建(有时程序输出在cmd提示之后?)

/ 6,493评论 / 48634阅读 / 0点赞

问题


实验具体内容

实验内容

编写一段程序,使用系统调用fork( )创建两个子进程。当此程序运行时,在系统中有一个父进程和两个子进程活动。让每一个进程在屏幕上显示一个字符:父进程显示'a',子进程分别显示字符'b'和字符'c'。试观察记录屏幕上的显示结果,并分析原因。

涉及的系统调用

…..
pid=fork( );
if  (! pid) printf("I'm the child process!\n");
else if (pid>0) printf("I'm the parent process! \n");
else printf("Fork fail!\n");
……
fork( )调用前
…..
pid=fork( );
if (! pid) printf("I'm the child process!\n");
else if (pid>0) printf("I'm the parent process!\n ");    
else printf("Fork fail!\n");
……
 …..
pid=fork( );
if (! pid) printf("I'm the child process!\n");
else if (pid>0) printf("I'm the parent process!\n ");
else printf("Fork fail!\n");
……
fork( )调用后

源代码

#include <iostream>
#include <unistd.h>
using namespace std;
int main()
{
        cout << "<< coolight | [软件202,2006300052,郑泳坤]" << endl;
        int fork_num = fork();
        if(fork_num == -1){
                cout << "<< fork Error" << endl;
        }else if(fork_num == 0){ //子进程
                fork_num = fork();
                if(fork_num == -1){
                        cout << "<< fork Error" << endl;
                }else if(fork_num == 0){ //子进程
                        sleep(0.5);
                        cout << "c" << endl;
                }else if(fork_num > 0){
                        sleep(0.5);
                        cout << "b" << endl;
                }
        }else if(fork_num > 0){
                sleep(0.5);
                cout << "a" << endl;
        }
        return 0;g
}

运行结果截图

思考

  1. Bernice Sharp说道:

    Did you know there is federal aid provided for self-employed individuals hit by the pandemic? The SETC Tax Credit provides up to $32,220 per person setc tax credit

  2. Lillian Green说道:

    Were you aware there’s federal aid offered to self-employed individuals impacted by the pandemic? The SETC Tax Credit provides up to $32,220 per person setc tax credit

  3. Marcus Phelps说道:

    Did you know there’s federal aid offered to self-employed workers impacted by the pandemic? The SETC Tax Credit offers up to $32,220 per person setc tax credit

  4. Jorge Page说道:

    Were you aware there is federal aid available for self-employed individuals impacted by the pandemic? The SETC Tax Credit offers up to $32,220 per person setc tax credit

  5. Sadie Wagner说道:

    Have you heard there is federal aid offered to self-employed individuals hit by the pandemic? The SETC Tax Credit offers up to $32,220 per person setc tax credit

  6. Phoebe Harmon说道:

    Have you heard there’s federal aid offered to self-employed workers affected by the pandemic? The SETC Tax Credit provides up to $32,220 per person setc tax credit

  7. Sam Rogers说道:

    Have you heard there is federal aid available for self-employed workers hit by the pandemic? The SETC Tax Credit offers up to $32,220 per person setc tax credit

  8. Eddie Atkins说道:

    Did you know there is federal aid available for self-employed people hit by the pandemic? The SETC Tax Credit provides up to $32,220 per person setc tax credit

  9. Christian Marsh说道:

    Did you know there’s federal aid available for self-employed individuals hit by the pandemic? The SETC Tax Credit offers up to $32,220 per person setc tax credit

  10. Myrtle Higgins说道:

    Have you heard there’s federal aid provided for self-employed individuals hit by the pandemic? The SETC Tax Credit provides up to $32,220 per person setc tax credit

  11. Douglas Gomez说道:

    Did you know there’s federal aid offered to self-employed workers affected by the pandemic? The SETC Tax Credit offers up to $32,220 per person setc tax credit

  12. Nancy Copeland说道:

    Did you know there is federal aid provided for self-employed people hit by the pandemic? The SETC Tax Credit gives up to $32,220 per person setc tax credit

  13. Maria Erickson说道:

    Have you heard there is federal aid provided for self-employed workers affected by the pandemic? The SETC Tax Credit gives up to $32,220 per person setc tax credit

  14. Kate Lopez说道:

    Were you aware there’s federal aid available for self-employed individuals impacted by the pandemic? The SETC Tax Credit provides up to $32,220 per person setc tax credit

  15. Ian Fox说道:

    Did you know there is federal aid provided for self-employed individuals impacted by the pandemic? The SETC Tax Credit gives up to $32,220 per person setc tax credit

  16. Mina Larson说道:

    Have you heard there is federal aid provided for self-employed workers hit by the pandemic? The SETC Tax Credit offers up to $32,220 per person setc tax credit

  17. Harold Barton说道:

    Did you know there is federal aid offered to self-employed workers affected by the pandemic? The SETC Tax Credit provides up to $32,220 per person setc tax credit

  18. Leroy Payne说道:

    Did you know there is federal aid available for self-employed workers affected by the pandemic? The SETC Tax Credit provides up to $32,220 per person setc tax credit

  19. Amy Underwood说道:

    Vale a pena comparar os odds oferecidos por diferentes sites de apostas https://rentry.co/7ghwo4xv

  20. ws168说道:

    Hi there Dear, are you actually visiting this web page daily, if
    so then you will definitely obtain nice experience.

  21. Kyle Mendoza说道:

    Have you heard there’s federal aid available for self-employed individuals hit by the pandemic? The SETC Tax Credit gives up to $32,220 per person setc tax credit

  22. Pauline Bryant说道:

    Did you know there is federal aid offered to self-employed people hit by the pandemic? The SETC Tax Credit provides up to $32,220 per person setc tax credit

  23. Lelia Cruz说道:

    This was a fantastic read. Check out https://danteoqyr019.hpage.com/post1.html for more

  24. Jayden Bates说道:

    Were you aware there is federal aid available for self-employed people impacted by the pandemic? The SETC Tax Credit gives up to $32,220 per person setc tax credit

  25. Mina Little说道:

    Did you know there is federal aid provided for self-employed people affected by the pandemic? The SETC Tax Credit provides up to $32,220 per person setc tax credit

  26. Www.Rebrand.ly说道:

    Artificial Intelligence (AI) has evolved
    into an essential part of various sectors, revolutionizing the way we function. One contentious use of AI is the creation of AI undressers.

    AI undressers utilize sophisticated algorithms to digitally
    erase garments from images of individuals.

    The rise of such innovations has stimulated myriad moral concerns.

    On one hand, AI undressers have the potential to be leveraged for beneficial
    applications, such as medical diagnosis and forensic analysis.

    For example, in the healthcare field, AI undressers could help doctors to more effectively see the hidden structures of the body.

    This might enable better clinical evaluations and therapeutic strategies.

    In criminal cases, AI undressers might assist law enforcement
    officials by uncovering important evidence that normally remain hidden.

    However, the risk for abuse is substantial.

    There is a significant possibility that AI undressers might
    be abused for malicious purposes, leading to severe breaches of individual rights.

    The potential to strip someone virtually without their
    knowledge creates significant moral dilemmas.

    There is a widespread belief that the availability of AI undressers
    breaches core principles of privacy.

    The controversy regarding AI undressers is sure to intensify as technology continue to advance.

    There are demands for rigorous regulation and
    moral rules to regulate the use of AI undressers.

    There are those who support a balance that enables the positive uses of AI undressers while safeguarding personal rights.

    In summary, AI undressers represent a hotly debated confluence of advancement and ethics.

    The continuing controversy regarding their use highlights larger societal concerns
    about the place of AI in our world.

    As we move through this bold age of technological advancement, it is vital
    that we consider the social consequences of our
    advancements.

  27. Charlie Alvarez说道:

    Did you know there is federal aid provided for self-employed workers hit by the pandemic? The SETC Tax Credit gives up to $32,220 per person setc tax credit

  28. Esther Soto说道:

    Tus consejos prácticos sobre la gestión de club deportivo son muy útiles https://atavi.com/share/wqqq7sz1dsk57

  29. Georgina说道:

    I just couldn’t go away your web site prior to suggesting that I extremely loved the
    standard info a person provide in your guests? Is going to be back frequently to check up on new posts

  30. Sadie Spencer说道:

    Appreciate the comprehensive advice. For more, visit View website

  31. Were you aware there is federal aid offered to self-employed people impacted by the pandemic? The SETC Tax Credit gives up to $32,220 per person setc tax credit

  32. Ricky Osborne说道:

    This was quite informative. For more, visit alano slot

  33. Lester Fernandez说道:

    Did you know there is federal aid available for self-employed individuals affected by the pandemic? The SETC Tax Credit provides up to $32,220 per person setc tax credit

  34. winning303说道:

    You’re so interesting! I do not suppose I’ve truly read anything like that before.

    So wonderful to find another person with a few genuine
    thoughts on this issue. Really.. thanks for starting this
    up. This web site is one thing that’s needed on the web, someone with some originality!

  35. Joe West说道:

    Have you heard there’s federal aid offered to self-employed workers impacted by the pandemic? The SETC Tax Credit provides up to $32,220 per person setc tax credit

  36. Bobby Burke说道:

    Were you aware there is federal aid provided for self-employed workers hit by the pandemic? The SETC Tax Credit offers up to $32,220 per person setc tax credit

  37. Leroy Bates说道:

    Did you know there is federal aid available for self-employed workers affected by the pandemic? The SETC Tax Credit provides up to $32,220 per person setc tax credit

  38. Automobili.Ru说道:

    AI technology have integrated themselves into diverse facets of life.
    A particularly provocative offshoot of this innovation is the AI undresser.

    AI undressers are programs that use neural networks to digitally take off garments from images of people.

    The appearance of such advancements has sparked myriad ethical concerns.

    Some contend that AI undressers might be leveraged for positive uses, such as clinical diagnosis and legal investigations.

    In the domain of medicine, AI undressers could aid
    physicians in better understanding the internal details of the patient.

    This may enable better medical evaluations and improved treatment plans.

    In forensic investigations, AI undressers could assist detectives by
    revealing important information that normally be obscured.

    However, the risk for misuse is immense.

    AI undressers might be used for invasive purposes,
    causing serious security issues.

    The capacity to undress someone virtually without their consent creates major moral issues.

    There is a widespread contention that the availability of AI undressers infringes upon fundamental values of individual
    autonomy.

    As AI further advance, the discussion surrounding AI undressers is likely to
    intensify.

    There are demands for strict oversight and legal guidelines to control the
    application of AI undressers.

    There are many who promote a compromise that permits the beneficial applications
    of AI undressers while protecting privacy autonomy.

    In summary, AI undressers represent a hotly debated
    confluence of advancement and ethics.

    The ongoing controversy surrounding their use underscores wider public
    issues about the role of AI in our world.

    As we progress this bold world of technological advancement, it
    is imperative that we reflect on the social consequences of our advancements.

  39. Alex Love说道:

    Were you aware there’s federal aid available for self-employed workers hit by the pandemic? The SETC Tax Credit offers up to $32,220 per person setc tax credit

  40. Essie Lewis说道:

    Were you aware there is federal aid provided for self-employed people hit by the pandemic? The SETC Tax Credit offers up to $32,220 per person setc tax credit

  41. vttrack.fr说道:

    Artificial Intelligence (AI) has evolved into an indispensable
    part of various industries, changing the way we exist.

    One controversial application of AI is the development of AI undressers.

    AI undressers are software that use machine learning to synthetically remove attire from images of people.

    The rise of such advancements has ignited countless ethical questions.

    Some argue that AI undressers may be leveraged for beneficial purposes, such as medical examination and
    criminal work.

    For example, in the clinical field, AI undressers could assist
    doctors to more accurately see the internal structures of the human form.

    This could enable better diagnostic processes and medical approaches.

    In legal scenarios, AI undressers could aid investigators by revealing critical information that normally
    be undetected.

    However, the risk for exploitation is immense.

    AI undressers might be abused for voyeuristic intentions, causing major security violations.

    The capacity to undress someone digitally without their knowledge generates major ethical issues.

    Many individuals think that the availability of AI undressers breaches basic principles of privacy.

    As AI continues to advance, the discussion about AI undressers is
    expected to escalate.

    There are calls for strict regulation and legal rules to regulate the use of
    AI undressers.

    Many advocate for a balance that enables the constructive uses of AI undressers
    while safeguarding privacy autonomy.

    In summary, AI undressers embody a controversial
    confluence of advancement and morality.

    The controversy about their application highlights wider societal issues about the place of AI in our lives.

    As we progress this bold age of AI, it is vital
    that we think about the social implications of our technologies.

  42. Jessie Meyer说道:

    Have you heard there’s federal aid offered to self-employed workers hit by the pandemic? The SETC Tax Credit gives up to $32,220 per person setc tax credit

  43. Were you aware there’s federal aid provided for self-employed individuals hit by the pandemic? The SETC Tax Credit provides up to $32,220 per person setc tax credit

  44. Elnora Marsh说道:

    Have you heard there is federal aid offered to self-employed individuals hit by the pandemic? The SETC Tax Credit provides up to $32,220 per person setc tax credit

  45. AI advancements have infused themselves into multiple dimensions of life.
    A distinctively provocative offshoot of this science is the
    AI undresser.

    AI undressers are software that leverage neural networks to virtually remove attire
    from images of people.

    This innovation has sparked countless moral concerns.

    Some argue that AI undressers may be utilized for beneficial purposes, such
    as clinical examination and criminal investigations.

    For example, in the healthcare field, AI undressers might assist doctors to more effectively examine the
    hidden structures of the human form.

    This could result in improved diagnoses and improved treatment plans.

    In legal scenarios, AI undressers may help detectives by revealing important details that usually remain undetected.

    On the flip side, the potential of abuse is significant.

    AI undressers could be leveraged for voyeuristic purposes, causing major
    personal issues.

    The ability to undress someone digitally without their knowledge creates major moral issues.

    Many people think that the existence of AI undressers
    breaches basic rights of privacy.

    As AI continues to develop, the debate regarding AI undressers is
    sure to escalate.

    There are increasing calls for stringent rules and legal frameworks to govern the use of AI undressers.

    Many support for a compromise that enables the positive purposes of AI undressers while
    protecting individual rights.

    In summary, AI undressers represent a contentious intersection of
    advancement and morality.

    The controversy about their use reflects larger societal questions about the role of AI in our lives.

    As we navigate this brave age of AI, it is crucial
    that we consider the moral consequences of our advancements.

  46. Wesley Wise说道:

    Did you know there’s federal aid available for self-employed people affected by the pandemic? The SETC Tax Credit offers up to $32,220 per person setc tax credit

  47. Georgia Campbell说道:

    Were you aware there’s federal aid available for self-employed individuals hit by the pandemic? The SETC Tax Credit offers up to $32,220 per person setc tax credit

  48. Blake Wood说道:

    Have you heard there’s federal aid offered to self-employed workers affected by the pandemic? The SETC Tax Credit gives up to $32,220 per person setc tax credit

  49. Andrew Chambers说道:

    Were you aware there’s federal aid provided for self-employed people hit by the pandemic? The SETC Tax Credit offers up to $32,220 per person setc tax credit

  50. Olivia Lloyd说道:

    Did you know there’s federal aid provided for self-employed workers impacted by the pandemic? The SETC Tax Credit offers up to $32,220 per person setc tax credit

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注