From: "John T. Williams" <jowillia@vt.edu>
To: Jose Luis Alarcon Sanchez <jlalarcon@bunniwerks.zzn.com>
Cc: linux-c-programming@vger.kernel.org
Subject: Re: How to execute a process in background by exec functions?
Date: 11 Apr 2004 13:05:00 -0400 [thread overview]
Message-ID: <1081703027.19558.5.camel@Marx.fesnel.no-ip.org> (raw)
In-Reply-To: <80BEFFCCAAE8E374782232F2462F1582@jlalarcon.bunniwerks.zzn.com>
The single quotes need to be double quotes
so the call should look like
execl("/bin/ls", "ls", 0);
On Sun, 2004-04-11 at 13:37, Jose Luis Alarcon Sanchez wrote:
> ---- Begin Original Message ----
> running a process in the background simply means not waiting for it to
> complete. So a parent process that wanted to make a child process run
> ls in the ´background¡ would do something like this: (again this should
> be treated as sudo code that just looks a lot like C)
>
> _______________________CODE__________________
> int
> main (int argC, char** argV) {
> int bg = 1; // test condition for running in the background
> int pid;
> int status;
>
> if( (pid = fork()) == 0 ) {
> /* child code starts here */
> execl(´/bin/ls¡, ´/bin/ls¡, 0 );
>
> } else {
> /* this is the critical point, if you call wait, the parent process
> stops until the child process returns, which would be fg behavior (at
> least in a shell). If the
> parent doesn't call wait (or waitpid), then both parent and child will
> run at the same time. (i.e. The child runs in the background */
> if( !bg) {
> wait(&status);
> }
> /* Parent Code Starts here */
> }
>
> return 0;
> }
> _________________________END CODE_____________________
>
> There are also considerations about input and output, and bringing the
> process from the background to the forground, and sending it back into
> the background, and so forth. If your really interested in how this
> works and how to address the more complex issues, I suggest that you
> read the source code for GNU BASH, which is freely available (at this
> point everyone must think I'm a spokes person for GNU) or Read the
> O'Reilly books "Learning the bash Shell, 2nd Edition", and "Practical
> C Programming, 3rd Edition"
> ---- End Original Message ----
>
>
> Hi John.
>
> I am trying compile the code you paste in your message,
> but i get an error with the line
>
> execl(´/bin/ls¡, ´/bin/ls¡, 0 );
>
> Process_Exec.c:15:11: warning: character constant too long for its type
> Process_Exec.c: In function `main':
> Process_Exec.c:15: error: `bin' undeclared (first use in this function)
> Process_Exec.c:15: error: (Each undeclared identifier is reported only
> once
> Process_Exec.c:15: error: for each function it appears in.)
> Process_Exec.c:15: error: stray '\241' in program
> Process_Exec.c:15: error: `ls' undeclared (first use in this function)
>
> I'm afraid that it is for the character before the '/',
> i can't get it with any key. But i am not sure, i am a very
> newbie C programmer.
>
> I hope you can help me.
>
> Thanks, very much, in advance.
>
> Regards.
>
> Jose.
>
>
> http://www.lordofunix.org
>
> FreeBSD RELEASE 5.2.
> Mandrake Linux 9.2 Kernel 2.6.2 XFS.
> Registered BSD User 51101.
> Registered Linux User #213309.
> Memories..... You are talking about memories.
> Rick Deckard. Blade Runner.
>
>
> Get your Free E-mail at http://bunniwerks.zzn.com
> ___________________________________________________________
> Get your own Web-based E-mail Service at http://www.zzn.com
> -
> To unsubscribe from this list: send the line "unsubscribe linux-c-programming" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
-
To unsubscribe from this list: send the line "unsubscribe linux-c-programming" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
next prev parent reply other threads:[~2004-04-11 17:05 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2004-04-11 17:37 How to execute a process in background by exec functions? Jose Luis Alarcon Sanchez
2004-04-11 17:05 ` John T. Williams [this message]
2004-04-11 23:02 ` Glynn Clements
-- strict thread matches above, loose matches on Subject: below --
2004-04-11 19:23 Jose Luis Alarcon Sanchez
[not found] <3AA03342E913FA4BA6D8BD0732BFC74B05530BA8@pdsmsx402.pd.intel.com>
2004-04-08 9:31 ` Wen Guangcheng
2004-04-06 20:44 c++ compiling problem. undefined reference to main srg
2004-04-08 5:41 ` How to execute a process in background by exec functions? Wen Guangcheng
2004-04-08 8:56 ` Glynn Clements
2004-04-08 13:25 ` John T. Williams
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1081703027.19558.5.camel@Marx.fesnel.no-ip.org \
--to=jowillia@vt.edu \
--cc=jlalarcon@bunniwerks.zzn.com \
--cc=linux-c-programming@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).