LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 06-03-2009, 08:59 AM   #1
eng2009
LQ Newbie
 
Registered: Apr 2009
Posts: 4

Rep: Reputation: 0
running ls in a "for"


Hello , I wish to run simply command like ls into a boucle for (to do other applications)
but I didn't succeed, what should i do
and thank you
my code is:



#include <stdio.h>
#include <memory.h>
#include <unistd.h>

int main(int argc, char **argv)
{

/* create the pipe */
int i, *status = 0;

char *parmList[] = { "ls", "-l", NULL };
/* create the child */
int pid;
if ((pid = fork()) < 0) {
printf("fork failed\n");
return 2;
}

if (pid == 0) {
/* child */
for (i = 1; i < 10; i++)
execvp("ls", parmList);
printf("ls failed"); /* if execlp returns, it's an error */
return 3;
} else {
/* parent */

printf("status parent avant est %d \n", status);
waitpid(pid, &status, 0);
printf("status parent apres est %d \n", status);
return 4;
}
return 0;
}
 
Old 06-03-2009, 09:53 AM   #2
noctilucent
Member
 
Registered: Jun 2009
Distribution: slackware
Posts: 123

Rep: Reputation: 34
Hello.

I don't think you understand what the exec* family of functions actually does. The man page of execvp (`man execvp`) might be of help.

P.S.: Perhaps this thread is more appropriate in the Programming sub-forum?
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Standard commands give "-bash: open: command not found" even in "su -" and "su root" mibo12 Linux - General 4 11-11-2007 10:18 PM
LXer: Displaying "MyComputer", "Trash", "Network Servers" Icons On A GNOME Desktop LXer Syndicated Linux News 0 04-02-2007 08:31 AM
what's the difference between running "id" and "id <username>"? hesher Linux - General 1 04-14-2005 07:04 PM
User "list" running process "python" TroelsSmit Linux - Newbie 2 02-22-2005 04:55 AM
error running "make" and "arkollonrc"... Toro Linux - Software 1 04-19-2004 12:24 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 08:00 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration