ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Distribution: MontaVista Linux Version 4.0.1, Professional Edition
Posts: 215
Original Poster
Rep:
Hi firstfire, thanks for your reply. I have to use the system due to my project.
Your parse function will come in useful thanks.
I have got the following working:
Not that this using the 'ls' command. I used this jsut to get it working. My Parent now prints out the ls output.
I cannot for the life of me get the ps -ef command working.
I have used the following:
You should supply execl() with a path to the program binary and a list of arguments to that program. Inside of `ps' this list is accessed via `char **argv'.
Here is an excerpt from `man exec':
Code:
int execl(const char *path, const char *arg, ...);
. . . . . . . . . . . . . . . . . .
The initial argument for these functions is the pathname of a file
which is to be executed.
The const char *arg and subsequent ellipses in the execl(), exe‐
clp(), and execle() functions can be thought of as arg0, arg1, ...,
argn. Together they describe a list of one or more pointers to
null-terminated strings that represent the argument list available
to the executed program. The first argument, by convention, should
point to the filename associated with the file being executed. The
list of arguments must be terminated by a NULL pointer, and, since
these are variadic functions, this pointer must be cast (char *)
NULL.
Note that you can not just "pipe" the data from ps to grep using exec because this involves running two processes and establishing a data channel between them, while exec is a low-level function only able to "run" one process. That's why
On the other hand `system(char *command)' and `popen()' are higher-level functions which pass given command to the shell, where actual processing is done (including redirections):
Code:
system("command") is equivalent to /bin/sh -c "command"
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.