关于循环内多个系统调用的新手问题 [英] Newbie Question about multiple system calls within loops

查看:71
本文介绍了关于循环内多个系统调用的新手问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好吧我正在尝试解决这个小问题我有我的程序等待

为第一个系统()调用完成开始下一个我将

只是扔我的意思的一个例子


在这个例子中等待第一个kedit关闭之前

打开第二个


#include< stdio.h>

#include< stdlib.h>

int main()

{$ / $

int count = 0;


while(count< = 5)

{

system(" kedit");

count ++;

}


返回0;


}

我想弄清楚的是让所有5个kedits一次打开,

一旦agian我相当新的我我只是想弄清楚基本的

概念,在这一个为什么它确实等到第一次调用

完成之后再做第二次

ok i am trying to solve this little problem i have my program waits
for the 1st system() call to finish before starting the next i will
just throw an example of what i mean out

in this example it waits for the 1st kedit to be closed before it
opens the second

#include <stdio.h>
#include <stdlib.h>
int main()
{

int count = 0;

while(count <= 5)
{
system("kedit");
count++;
}

return 0;

}
what i would like to figure out is to make all 5 kedits open at once,
once agian i am fairly new i am just trying to figure out basic
concepts and in this one why exactly it waits for the 1st call to
finish before making the second

推荐答案

6月26日上午8:01,student.m ... @ g mail.com写道:
On Jun 26, 8:01 am, student.m...@gmail.com wrote:

ok我正在尝试解决这个小问题我有我的程序等待

为第一个系统()调用在开始下一个之前完成我将

只是举一个例子我的意思是
ok i am trying to solve this little problem i have my program waits
for the 1st system() call to finish before starting the next i will
just throw an example of what i mean out



你不应该使用术语系统调用什么时候你实际上是b $ b意味着调用系统库函数。

You should not be using the term system call when what you actually
mean is invoking the system library function.


在此示例中等待第一个kedit关闭之前

打开第二个
in this example it waits for the 1st kedit to be closed before it
opens the second



您是否考虑过查看system()的文档?


NAME

system - 执行shell命令


大纲

#include< stdlib.h>


int system(const char * command);


描述

system()通过调用/

bin / sh -c命令执行命令中指定的命令,并在
命令已经完成。在执行命令期间,

SIGCHLD将被阻止,SIGINT和

SIGQUIT将被忽略。


我发布Linux手册页,但基本的想法适用于任何

平台。 system()将不会返回,除非您通过系统调用的命令已经完成。

Did you consider looking at the documentation for system() ?

NAME
system - execute a shell command

SYNOPSIS
#include <stdlib.h>

int system(const char *command);

DESCRIPTION
system() executes a command specified in command by calling /
bin/sh -c command, and returns after the
command has been completed. During execution of the command,
SIGCHLD will be blocked, and SIGINT and
SIGQUIT will be ignored.

I am posting Linux man pages but the basic idea holds true for any
platform. system() will not return until and unless the command you
have invoked through system is completed.


st ********** @ gmail.com schrieb:
st**********@gmail.com schrieb:

我想弄清楚的是让所有5个kedits一次打开,

一旦agian我相当新,我只想弄清楚基本

概念,在这一个为什么它等待第一次调用

完成后才能获得第二个
what i would like to figure out is to make all 5 kedits open at once,
once agian i am fairly new i am just trying to figure out basic
concepts and in this one why exactly it waits for the 1st call to
finish before making the second



看看fork / exec 。


请注意,这个问题最好属于

comp.os.linux.development.system(或者你正在使用的系统)。

你可能会在这里大吼大叫,因为这个小组处理的是C语言的
(不是C语言中的系统编程)。


问候,

约翰内斯


-

" Wer etwas kritisiert muss es noch lange nicht selber besser k?nnen。 Es

reicht zu wissen,da? andere es besser k?nnen und andere es auch

besser machen um einen Vergleich zu bringen。 - Wolfgang Gerber

in de.sci.electronics< 47 *********************** @ news.freenet.de>

Have a look at fork/exec.

Note that this question better belongs to
comp.os.linux.development.system (or the system you''re working with).
You''re probably gonna get yelled at here because this group deals with
the C language (not the system programming in C).

Regards,
Johannes

--
"Wer etwas kritisiert muss es noch lange nicht selber besser k?nnen. Es
reicht zu wissen, da? andere es besser k?nnen und andere es auch
besser machen um einen Vergleich zu bringen." - Wolfgang Gerber
in de.sci.electronics <47***********************@news.freenet.de>


st ********** @ gmail.com 写道:

ok我正在尝试解决这个小问题我有我的程序等待

for the第一个系统()调用完成,然后开始下一个我将

只是举一个例子我的意思


在这个例子中等待第一个kedit在它关闭之前

打开第二个

#include< stdio.h>

#include< stdlib .h>

int main()

{


int count = 0;


while(count< = 5)

{

system(" kedit");

count ++;

}


返回0;


}


我想要什么弄清楚是让所有5个kedits一次打开,

一次gian我是相当新的我只是想弄清楚基本的

概念,在这一个为什么它等到第一次调用

完成后才能获得第二个
ok i am trying to solve this little problem i have my program waits
for the 1st system() call to finish before starting the next i will
just throw an example of what i mean out

in this example it waits for the 1st kedit to be closed before it
opens the second

#include <stdio.h>
#include <stdlib.h>
int main()
{

int count = 0;

while(count <= 5)
{
system("kedit");
count++;
}

return 0;

}
what i would like to figure out is to make all 5 kedits open at once,
once agian i am fairly new i am just trying to figure out basic
concepts and in this one why exactly it waits for the 1st call to
finish before making the second



根据定义,在完成命令

之前,system()不会返回。


您的系统可能有某种方式来分离一个shell命令,以便

system()将立即返回(例如kedit&),但这本身就是

非便携式。同样地,它可能有其他方法来做同样的事情

没有system(),例如fork()/ exec(),但那些也是不可移植的。


如果你愿意将你的程序限制在POSIX环境,那么

你可能希望利用POSIX(非C)标准提供的一些额外功能

,但这里的主题不在此。


S

By definition, system() does not return until the command has been
completed.

Your system may have some way to "detach" a shell command so that
system() will return immediately (e.g. "kedit &"), but that''s inherently
non-portable. Likewise, it may have other ways to do the same thing
without system(), e.g. fork()/exec(), but those are also non-portable.

If you are willing to restrict your program to POSIX environments, then
you may wish to take advantage of some of the additional functionality
available from the POSIX (not C) standard, but that''s off-topic here.

S


这篇关于关于循环内多个系统调用的新手问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆