03-26-2004
forks....HELP!!! someone anyone?
Hey guys,
I'm given this bit of code, but, I'm having some problems executing it with the functions I've defined so far. I'm suppose to define the funtions "parse" and "execute." Parse splits the command in buf into individual arguments. It strips whitespace, replacing those it finds with NULLS thereby defining where an argument ends.
How would I create the function execute using 'execvp' which creates a child process with the commands developed in the function parse?
The code is:
.................................................................................................... .....
#define MAX 512
void parse(char* buf, char** args);
void execute(char** args);
int main()
{
char buf[MAX];
char* args[64];
for ( ; ; )
{
/* prompt for a read a command */
printf(“Command: “);
if(fgets(buf, MAX,stdin) == ‘\0')
{
printf(“\n”);
exit(0);
}
/* Split the command string into arguments */
parse(buf, args);
/* Execute the command. */
execute(args);
}
return 0;
}
.................................................................................................... .....
Thankx in advance.....
5 More Discussions You Might Find Interesting
1. Programming
Hi, so I've got this program("main") that fork executes another ("user"). These programs communicate through fifos.
One communication is a spawn call, where user passes an executable, main forks and executes it. So, I'm keeping track of all my processes using a task table. After the fork (for... (6 Replies)
Discussion started by: Funktar
6 Replies
2. UNIX for Advanced & Expert Users
I am trying to figure out why when i have the following code
int main( { printf("0\n"); fork(); printf("1\n"); exit(0);}
and type in the shell
a.out | cat
the output of this program is
0
1
0
1
instead of
0
1
1
does anyone know? (3 Replies)
Discussion started by: Phantom12345
3 Replies
3. Programming
Hello *NIX gurus,
I have a slight perplexing problem with multiple forks giving different results... Here is the deal.
From what I undestand, a fork() call starts executing from the next instruction that follows the fork() call. That means it inherits the PC counter register value of the... (4 Replies)
Discussion started by: navigator
4 Replies
4. Programming
i'm tring to make 2 processes each read from the same file but only one of them read the file.
FILE * fileptr1;
fileptr1 = fopen("file1.txt","rt");
pid2=fork();
while(1)
{
fscanf(fileptr1,"%s",temp1);
if(feof(fileptr1)==0)
{
printf("%i",getpid()); //id of current process ... (6 Replies)
Discussion started by: ddx08
6 Replies
5. Shell Programming and Scripting
all,
i've been reading to try and get an abstract idea of the process effeciency of commands , sed, bash, perl, awk, find, grep, etc
which processes will spawn?, fork?, launch subshell?, etc and under what conditions?
how do you know which commands have the faster and better stdio... (2 Replies)
Discussion started by: f77hack
2 Replies
el(1) General Commands Manual el(1)
NAME
el -- program to make a tuned shell-command for Oneliner
SYNOPSIS
el [-acdfhioxV] [--command cmd] [--args n] [--format fmt] [--execute] [--inpipe buf] [--outpipe buf] [--serial] [--help] [--ver-
sion] [--debug]
DESCRIPTION
This manual page documents briefly the el command.
This manual page was written for the Debian distribution because the original program does not have a manual page. Instead, it has docu-
mentation in the GNU Info format; see below.
el is a program that You can make a tuned shell-command for Oneliner with. This command can send S-exp to Emacs, and this can make Emacs
evaluate it, too. In other words, you can execute Emacs's function from shell-commands. And you can make Emacs work in closer cooperation
with your favorite shell-commands.
OPTIONS
These programs follow the usual GNU command line syntax, with long options starting with two dashes (`-'). A summary of options is
included below. For a complete description, see the Info files.
-c cmd --command cmd
cmd means a function of Elisp. Command line arguments and data from stdin means arguments of cmd. If you specify the only -c
switch, el output one S-exp by one line of stdin.
--a n --args n
Specifies the maximum number of arguments of a Elisp function with -c switch.
-f fmt --format fmt
Allows you to use format string of printf for making a S-exp.
-x --execute
Requests to Oneliner to evaluate the S-exp to use *Oneliner auto-eval* buffer.
-i buf --inpipe buf
Gets input from pipe-buffer. You can specify a number of pipe-buffer, too.
-o buf --outpipe buf
Puts output to pipe-buffer. You can specify a number of pipe-buffer, too.
-s --serial
Makes el to serialize multiple lines to one line.
-h --help
Display help message.
-V --version
Display version identifiers.
-d --debug
Enable debugging state.
SEE ALSO
The programs are documented fully by Oneliner(Shell-mode hooks for Oneliners) available via the Info system.
AUTHOR
This manual page was written by OHURA Makoto <ohura@debian.org> for the Debian system (but may be used by others). Permission is granted
to copy, distribute and/or modify this document under the terms of the GNU General Public License, Version 2 any later version published by
the Free Software Foundation.
On Debian systems, the complete text of the GNU General Public License can be found in /usr/share/common-licenses/GPL.
el(1)