c coding on linux

Reply

Join Date: Feb 2007
Posts: 1
Reputation: rasakse is an unknown quantity at this point 
Solved Threads: 0
rasakse rasakse is offline Offline
Newbie Poster

c coding on linux

 
0
  #1
Feb 4th, 2007
someone please help me on how to run this coding using knoppix linux.. using c language.. i really need help.. i want to know.. what is the output.. this is the coding :-
  1. int main()
  2. {
  3. Pid_t pid;
  4. /* fork another process */
  5. pid=fork();
  6.  
  7. if (pid<0)
  8. {
  9. /* error occured */
  10. fprintf (stderr,"fork failed");
  11. exit(-1);
  12. }
  13. else if (pid==0)
  14. {
  15. /* child process */
  16. execlp("/bin/ls","ls",NULL);
  17. }
  18. else
  19. {
  20. /* parent process */
  21. /* parent will wait for child to complete */
  22. wait (NULL);
  23. printf ("Child Complete");
  24. exit(0);
  25. }
  26. }

-please, i need your help
Last edited by Ancient Dragon; Feb 4th, 2007 at 4:27 am. Reason: add code tags
Reply With Quote Quick reply to this message  
Join Date: Dec 2006
Posts: 209
Reputation: Ravalon is on a distinguished road 
Solved Threads: 15
Ravalon's Avatar
Ravalon Ravalon is offline Offline
Posting Whiz in Training

Re: c coding on linux

 
0
  #2
Feb 4th, 2007
Originally Posted by rasakse View Post
someone please help me on how to run this coding using knoppix linux.. using c language.. i really need help.. i want to know.. what is the output.. this is the coding :-
  1. int main()
  2. {
  3. Pid_t pid;
  4. /* fork another process */
  5. pid=fork();
  6.  
  7. if (pid<0)
  8. {
  9. /* error occured */
  10. fprintf (stderr,"fork failed");
  11. exit(-1);
  12. }
  13. else if (pid==0)
  14. {
  15. /* child process */
  16. execlp("/bin/ls","ls",NULL);
  17. }
  18. else
  19. {
  20. /* parent process */
  21. /* parent will wait for child to complete */
  22. wait (NULL);
  23. printf ("Child Complete");
  24. exit(0);
  25. }
  26. }

-please, i need your help
What happens when you run it?
It's hard to be humble when you're as gifted as I am at pretending to be an expert.
Reply With Quote Quick reply to this message  
Join Date: Apr 2006
Posts: 5,051
Reputation: John A is a splendid one to behold John A is a splendid one to behold John A is a splendid one to behold John A is a splendid one to behold John A is a splendid one to behold John A is a splendid one to behold John A is a splendid one to behold John A is a splendid one to behold 
Solved Threads: 332
Team Colleague
John A's Avatar
John A John A is offline Offline
Vampirical Lurker

Re: c coding on linux

 
0
  #3
Feb 4th, 2007
It probably will, although you'll need the lines
  1. #include <sys/types.h>
  2. #include <unistd.h>
at the top of your program to have the slightest chance of compiling it.
"Technological progress is like an axe in the hands of a pathological criminal."
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the C Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC