home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #30 / NN_1992_30.iso / spool / comp / lang / c / 18385 < prev    next >
Encoding:
Text File  |  1992-12-15  |  1.5 KB  |  81 lines

  1. Path: sparky!uunet!psgrain!hippo!ee.und.ac.za!csir.co.za!olsa99!infow02!andrewr
  2. From: andrewr@infoware.co.za (Andrew Roos)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: fork() and wait() problem...Please HELP!
  5. Message-ID: <1992Dec15.093050.1242@infoware.co.za>
  6. Date: 15 Dec 92 09:30:50 GMT
  7. References: <&hc1Ha#a$a@atlantis.psu.edu>
  8. Organization: Infoware (Pty) Ltd
  9. Lines: 70
  10.  
  11. newton@wilbur.psu.edu (Cynthia Newton) writes:
  12.  
  13. >In the following  program, if I want to edit the file more than than
  14. >once, most of the time 'vi' just freezes.
  15.  
  16. >Could you tell how to handle this kind of situation correctly?
  17. >I don't want to use system().
  18.  
  19. >I use SunOS 4.1.1
  20.  
  21. >Thanks.
  22.  
  23. >-----------------------------
  24. >#include <stdio.h>
  25.  
  26. >main()    {
  27. >    int pid;
  28. >    int ch;
  29.  
  30. >for(;;){
  31. >    ch=chh();
  32. >switch(ch)
  33. >{
  34. >    case 1:
  35. >    pid=fork();
  36. >    if(pid==0){
  37. >    execl("/usr/ucb/vi","vi","file",NULL);
  38. >}
  39. >wait();
  40. >break;
  41. >    case 2:
  42. >    exit();
  43. >}
  44. >}
  45.  
  46. >}
  47.  
  48. >chh()
  49. >{
  50. >int c;
  51. >char s[10];
  52. >fprintf(stderr,"1. edit\n");
  53. >fprintf(stderr,"2. exit\n");
  54.  
  55. >do{
  56. >fprintf(stderr,"Enter Choice: ");
  57. >gets(s);
  58. >c=atoi(s);
  59. >}while(c<0 || c>2);
  60. >return c;
  61. >}
  62. >--------------------------------------
  63. >-- 
  64. >C Newton
  65.  
  66. Hi Cynthia
  67.  
  68. I don't know if this is the problem, but your call to wait() is incorrect.
  69. Wait expects a pointer to int as an argument, which is where it stores the
  70. status of the child process which terminated. You can modify it to:
  71.  
  72. wait((int*)0)
  73.  
  74. if you are not interested in the status. It is possible that the status
  75. value is being written to an arbitary address which may be corrupting 
  76. something. 
  77.  
  78. Hope this helps
  79.  
  80. Andrew Roos
  81.