943,612 Members | Top Members by Rank

Ad:
  • C Discussion Thread
  • Unsolved
  • Views: 4721
  • C RSS
Feb 4th, 2007
0

c coding on linux

Expand 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
Last edited by Ancient Dragon; Feb 4th, 2007 at 4:27 am. Reason: add code tags
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
rasakse is offline Offline
1 posts
since Feb 2007
Feb 4th, 2007
0

Re: c coding on linux

Click to Expand / Collapse  Quote originally posted by rasakse ...
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?
Reputation Points: 84
Solved Threads: 15
Posting Whiz in Training
Ravalon is offline Offline
209 posts
since Dec 2006
Feb 4th, 2007
0

Re: c coding on linux

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.
Team Colleague
Reputation Points: 2240
Solved Threads: 338
Vampirical Lurker
John A is offline Offline
5,055 posts
since Apr 2006

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C Forum Timeline: WinSNMP
Next Thread in C Forum Timeline: implement semaphore without the use of while or any if statement





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC