473,399 Members | 3,401 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

Newbie Question about multiple system calls within loops

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
Jun 27 '08 #1
23 2106
On Jun 26, 8:01 am, student.m...@gmail.com wrote:
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
You should not be using the term system call when what you actually
mean is invoking the system library function.
in this example it waits for the 1st kedit to be closed before it
opens the second
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.
Jun 27 '08 #2
st**********@gmail.com schrieb:
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
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>
Jun 27 '08 #3
st**********@gmail.com wrote:
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
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
Jun 27 '08 #4
On Jun 26, 6:02 pm, Stephen Sprunk <step...@sprunk.orgwrote:
student.m...@gmail.com wrote:
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

By definition, system() does not return until the command has been
completed.
By whose definition? Certainly not ISO 9899:1999's.
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
system("kedit &") is as portable as system("kedit")
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.
Agreed. It's topical in comp.unix.programmer, so OP can try that group
for POSIX questions.
Jun 27 '08 #5
On Jun 26, 5:34 pm, vipps...@gmail.com wrote:
On Jun 26, 6:02 pm, Stephen Sprunk <step...@sprunk.orgwrote:
student.m...@gmail.com wrote:
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
By definition, system() does not return until the command has been
completed.

By whose definition? Certainly not ISO 9899:1999's.
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

system("kedit &") is as portable as system("kedit")
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.

Agreed. It's topical in comp.unix.programmer, so OP can try that group
for POSIX questions.
Thanks for all the responses sorry for posting here, but the
system("kedit &"); did work read the man on system() little bit better
understanding of whats going on. i looked up 10 different
documentations on fork/exec it seems a little complicated just yet

but thanks for the help
Jun 27 '08 #6
On 26 Jun 2008 at 19:13, st**********@gmail.com wrote:
student.m...@gmail.com wrote:
what i would like to figure out is to make all 5 kedits open at once,

Thanks for all the responses sorry for posting here, but the
system("kedit &"); did work read the man on system() little bit better
understanding of whats going on. i looked up 10 different
documentations on fork/exec it seems a little complicated just yet
It's really not all that complicated. Here's a simple example that
addresses your original question:
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>

int main(void)
{
pid_t pid;
int count;
for(count=0; count<5; count++) {
pid=fork();
if (pid==0) {
/* child process */
execlp("kedit", "kedit", (char *) NULL);
perror("exec failure");
exit(1);
}
}
return 0;
}

Jun 27 '08 #7
On Jun 26, 12:28*pm, Antoninus Twink <nos...@nospam.invalidwrote:
On 26 Jun 2008 at 19:13, student.m...@gmail.com wrote:
student.m...@gmail.com wrote:
what i would like to figure out is to make all 5 kedits open at once,
Thanks for all the responses sorry for posting here, but the
system("kedit &"); did work read the man on system() little bit better
understanding of whats going on. i looked up 10 different
documentations on fork/exec it seems a little complicated just yet

It's really not all that complicated. Here's a simple example that
addresses your original question:

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>

int main(void)
{
* pid_t pid;
* int count;
* for(count=0; count<5; count++) {
* * pid=fork();
* * if (pid==0) {
* * * /* child process */
* * * execlp("kedit", "kedit", (char *) NULL);
Maybe I misunderstood section 8.10 in the book "Advance Programming in
the Unix Environment" by Stevens and Rago, but I believe
(char *)NULL actually creates undefined behavior when it's passed to
the exec() family.
* * * perror("exec failure");
* * * exit(1);
* * }
* }
* return 0;
I thought it was supposed to be exit(0) and not

return 0

in this case.
>

}- Hide quoted text -
Jun 27 '08 #8
On Jun 26, 12:28*pm, Antoninus Twink <nos...@nospam.invalidwrote:
On 26 Jun 2008 at 19:13, student.m...@gmail.com wrote:
student.m...@gmail.com wrote:
what i would like to figure out is to make all 5 kedits open at once,
Thanks for all the responses sorry for posting here, but the
system("kedit &"); did work read the man on system() little bit better
understanding of whats going on. i looked up 10 different
documentations on fork/exec it seems a little complicated just yet

It's really not all that complicated. Here's a simple example that
addresses your original question:

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>

int main(void)
{
* pid_t pid;
* int count;
* for(count=0; count<5; count++) {
* * pid=fork();
* * if (pid==0) {
* * * /* child process */
* * * execlp("kedit", "kedit", (char *) NULL);
* * * perror("exec failure");
* * * exit(1);
* * }
* }
* return 0;

}- Hide quoted text -

- Show quoted text -
And off course this is again off topic. So not only does this troll
fail to understand that this is a C forum, but this person writes
questionable simple *nix code.
Jun 27 '08 #9
Chad <cd*****@gmail.comwrites:
On Jun 26, 12:28*pm, Antoninus Twink <nos...@nospam.invalidwrote:
[...]
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>

int main(void)
{
pid_t pid;
int count;
for(count=0; count<5; count++) {
pid=fork();
if (pid==0) {
/* child process */
execlp("kedit", "kedit", (char *) NULL);

Maybe I misunderstood section 8.10 in the book "Advance Programming in
the Unix Environment" by Stevens and Rago, but I believe
(char *)NULL actually creates undefined behavior when it's passed to
the exec() family.
<OT>No, it's correct; it's used to mark the end of the arguments.</OT>
perror("exec failure");
exit(1);
}
}
return 0;
I thought it was supposed to be exit(0) and not

return 0

in this case.
Within main(), ``exit(0)'' and ``return 0'' are almost exactly
equivalent.

exit(1) is non-portable (the only portable exit arguments are 0,
EXIT_SUCCESS, and EXIT_FAILURE), but the code is non-portable anyway.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Jun 27 '08 #10
On Thu, 26 Jun 2008 17:20:50 -0700 (PDT),
Chad <cd*****@gmail.comwrote:
On Jun 26, 12:28*pm, Antoninus Twink <nos...@nospam.invalidwrote:
>On 26 Jun 2008 at 19:13, student.m...@gmail.com wrote:
>* * * execlp("kedit", "kedit", (char *) NULL);

Maybe I misunderstood section 8.10 in the book "Advance Programming in
the Unix Environment" by Stevens and Rago, but I believe
(char *)NULL actually creates undefined behavior when it's passed to
the exec() family.
\begin{offtopic}

I think you've got it the wrong way around. The last argument in the
variable list _has_ to be cast to char *.

This is, of course, not a standard C function, but a POSIX one, and
therefore it'd be better to discuss its interface on
comp.unix.programmer, rather than here. It is probably a good idea to
check http://www.opengroup.org/onlinepubs/...ions/exec.html
and your system's man page before you ask the people there.

\end{offtopic}

Martien
--
|
Martien Verbruggen | It's not what we don't know that hurts us,
| it's what we know for certain that just ain't
| so. -- Mark Twain
Jun 27 '08 #11
Antoninus Twink wrote:
On 26 Jun 2008 at 19:13, st**********@gmail.com wrote:
>>>student.m...@gmail.com wrote:
what i would like to figure out is to make all 5 kedits open at once,
Thanks for all the responses sorry for posting here, but the
system("kedit &"); did work read the man on system() little bit better
understanding of whats going on. i looked up 10 different
documentations on fork/exec it seems a little complicated just yet

It's really not all that complicated. Here's a simple example that
addresses your original question:
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>

int main(void)
{
pid_t pid;
int count;
for(count=0; count<5; count++) {
pid=fork();
if (pid==0) {
/* child process */
execlp("kedit", "kedit", (char *) NULL);
perror("exec failure");
exit(1);
}
}
return 0;
}
<OT>
If you're having trouble figuring out what's going on above, consider
this primitive (and buggy) implementation of system():

int system(const char *command) {
pid_t pid = fork();
if (!pid) {
execlp(command, (char *)NULL);
return -1;
} else {
return waitpid(pid, NULL, 0);
}
}

Since the OP was looking to remove the waitpid() part of system(), the
most logical answer is to use fork()/exec() directly.

Once you wrap your head around the concepts that fork() returns twice
and exec() never returns (assuming everything works properly), the whole
process is rather obvious.
</OT>

S
Jun 29 '08 #12
Chad wrote:
Antoninus Twink <nos...@nospam.invalidwrote:
.... snip ...
>
>It's really not all that complicated. Here's a simple example
that addresses your original question:
.... snip twink gubris ...
>
And off course this is again off topic. So not only does this
troll fail to understand that this is a C forum, but this person
writes questionable simple *nix code.
That troll understands very well. Its only objective is to disrupt
the newsgroup. Just PLONK it. To do so, get a real newsreader,
such as Thunderbird, and abandon google.

--
[mail]: Chuck F (cbfalconer at maineline dot net)
[page]: <http://cbfalconer.home.att.net>
Try the download section.

Jun 29 '08 #13
CBFalconer wrote:
Chad wrote:
>Antoninus Twink <nos...@nospam.invalidwrote:
... snip ...
>>
>>It's really not all that complicated. Here's a simple example
that addresses your original question:
... snip twink gubris ...
I suppose you meant hubris here?

<snip>

Jun 29 '08 #14
On Sun, 29 Jun 2008 08:56:57 +0530, santosh <sa*********@gmail.com>
wrote:
I suppose you meant hubris here?
gubris is the GNU implementation of ISO standard hubris.

Tony
Jun 30 '08 #15
In article <l8********************************@4ax.com>,
Tony Mc <af***@btinternet.comwrote:
>On Sun, 29 Jun 2008 08:56:57 +0530, santosh <sa*********@gmail.com>
wrote:
>I suppose you meant hubris here?
>gubris is the GNU implementation of ISO standard hubris.
Not quite: it is the GNU implementation of something -like-
ISO standard hubris, but with extensions that
violate constraints in the ISO standard hubris, with the
extensions turned on by default (under the excuse that
since gubris does not claim to be ISO standard hubris, the
ISO standard's constraints have no authority over gubris.)
--
So you found your solution
What will be your last contribution?
-- Supertramp (Fool's Overture)
Jun 30 '08 #16
Walter Roberson wrote:
In article <l8********************************@4ax.com>,
Tony Mc <af***@btinternet.comwrote:
>>On Sun, 29 Jun 2008 08:56:57 +0530, santosh <sa*********@gmail.com>
wrote:
>>I suppose you meant hubris here?
>>gubris is the GNU implementation of ISO standard hubris.

Not quite: it is the GNU implementation of something -like-
ISO standard hubris, but with extensions that
violate constraints in the ISO standard hubris, with the
extensions turned on by default (under the excuse that
since gubris does not claim to be ISO standard hubris, the
ISO standard's constraints have no authority over gubris.)
Given all this, I'm surprised that CBFalconer endorses implementation
specific extensions in this group, which, as he himself so often
observes, is for ISO standard hubris. :-)

Jun 30 '08 #17
Walter Roberson wrote:
In article <l8********************************@4ax.com>,
Tony Mc <af***@btinternet.comwrote:
>>On Sun, 29 Jun 2008 08:56:57 +0530, santosh <sa*********@gmail.com>
wrote:
>>I suppose you meant hubris here?
>>gubris is the GNU implementation of ISO standard hubris.

Not quite: it is the GNU implementation of something -like-
ISO standard hubris, but with extensions that
violate constraints in the ISO standard hubris, with the
extensions turned on by default (under the excuse that
since gubris does not claim to be ISO standard hubris, the
ISO standard's constraints have no authority over gubris.)
Given all this, I'm surprised that CBFalconer endorses implementation
specific extensions in this group, which, as he himself so often
observes, is for ISO standard hubris. :-)

Jun 30 '08 #18
santosh wrote:
>
.... snip ...
>
Given all this, I'm surprised that CBFalconer endorses
implementation specific extensions in this group, which, as he
himself so often observes, is for ISO standard hubris. :-)
I suspect you have seriously misinterpreted something. Try making
specific statements.

--
[mail]: Chuck F (cbfalconer at maineline dot net)
[page]: <http://cbfalconer.home.att.net>
Try the download section.
Jul 1 '08 #19
santosh wrote:
CBFalconer
I noticed that you also brought up Jacob's name
in another thread today, in a similarly stupid way.

--
pete
Jul 1 '08 #20
CBFalconer wrote:
santosh wrote:
>>
... snip ...
>>
Given all this, I'm surprised that CBFalconer endorses
implementation specific extensions in this group, which, as he
himself so often observes, is for ISO standard hubris. :-)

I suspect you have seriously misinterpreted something. Try making
specific statements.
It was in jest. That's why I put the smiley there. In any case,
apologies if I have offended you.

Jul 1 '08 #21
pete wrote:
santosh wrote:
> CBFalconer

I noticed that you also brought up Jacob's name
in another thread today, in a similarly stupid way.
Both were attempts at humour, but I guess it failed.

Jul 1 '08 #22
santosh wrote:
pete wrote:
>santosh wrote:
>> CBFalconer

I noticed that you also brought up Jacob's name
in another thread today, in a similarly stupid way.

Both were attempts at humour, but I guess it failed.
I don't recall seeing Jacobs response, if any. However I suspect
mine was considerably calmer. :-)

--
[mail]: Chuck F (cbfalconer at maineline dot net)
[page]: <http://cbfalconer.home.att.net>
Try the download section.
Jul 1 '08 #23
CBFalconer wrote:
santosh wrote:
>pete wrote:
>>santosh wrote:

CBFalconer

I noticed that you also brought up Jacob's name
in another thread today, in a similarly stupid way.

Both were attempts at humour, but I guess it failed.

I don't recall seeing Jacobs response, if any. However I suspect
mine was considerably calmer. :-)
s/considerably/a shade/ 8-)

Bye, Jojo
Jul 1 '08 #24

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

54
by: Brandon J. Van Every | last post by:
I'm realizing I didn't frame my question well. What's ***TOTALLY COMPELLING*** about Ruby over Python? What makes you jump up in your chair and scream "Wow! Ruby has *that*? That is SO...
15
by: Jacek Generowicz | last post by:
I have a multiple disptacher which, conceptually, looks something like this: class Multimethod: def __init__(self): self.methods = {}
3
by: Jack | last post by:
On the 1st of January 1998, Bjarne Stroustrup gave an interview to the IEEE's 'Computer' magazine. Naturally, the editors thought he would be giving a retrospective view of seven years of...
81
by: Matt | last post by:
I have 2 questions: 1. strlen returns an unsigned (size_t) quantity. Why is an unsigned value more approprate than a signed value? Why is unsighned value less appropriate? 2. Would there...
0
by: Jonathan Duke | last post by:
I have written a custom session state provider that stores session data in XML in a SQL database , and I was running the SQL profiler to verify that all of my stored procedures were called in the...
1
by: kiplring | last post by:
List<string> effectList = new List<string>(); effectList.Clear(); effectList = null; using (List<string> effectList = new List<string>()) { } If there are so many calls, I should save as...
6
by: BostonNole | last post by:
I am using SQL 2000 and VB.NET (VS 2005). I have three stored procedure: sp_A, sp_B and sp_C I need to be able to call sp_A once and sp_B and sp_C 1 to n number of times all within a single...
0
by: abev | last post by:
I have a table adapter with multiple queries. I have code that calls many of these queries (stored procedures) within a For...Next loop. It reuses the declared object many times. Should I be...
6
Markus
by: Markus | last post by:
Things to discuss: Headers What are they? What does PHP have to do with headers? Why can they only be sent before any output? Common causes
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.