sigaction and waitpid causes "interrupted system call" when calling fgets()



Hi,

I'm using ubuntu 7.10.

I'm trying to run "ls" in the background while I continue to receive
input.
I also want to do something when "ls" finishes.

The program loops and waits for input.
Whenever it receives input, it does the following.

The parent calls fork().
The child uses execvp to run "ls".
The parent doesn't call waitpid()

An error happens when I call fgets(). Any help is appreciated.

Below is the code:
--------------------------------------------------------------------------------------
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/wait.h>

void signal_handler(int signo, siginfo_t *info, void *context)
{ //do nothing
}

void install_sigaction_handler()
{
struct sigaction sa;

sa.sa_sigaction = signal_handler;
sigemptyset(&sa.sa_mask);
sa.sa_flags = SA_SIGINFO;
sigaction(SIGCHLD, &sa, NULL);
}

void ls()
{
char *argv[2];
argv[0] = "ls";
argv[1] = NULL;

int pid;
pid = fork();

if (pid == -1)
abort();

if (pid == 0)
{ execvp(argv[0], argv);
abort();
}
else
{
//if the parent doesn't call waitpid(pid,NULL,0);, we're in trouble
}
}

int main(void)
{
char input[1024];

//install a signal action handler
install_sigaction_handler();

//loop to receive input
while (!feof(stdin))
{
printf("enter something :");
fflush(stdout);

if (fgets(input, 1024, stdin) == NULL)
{
if (ferror(stdin))
perror("my program error : ");
break;
}

//fork a child and run "ls"
//parent doesn't call waitpid
ls();
}

return 0;
}
------------------------------------------------------------
.



Relevant Pages

  • Re: Crash on creation of OpenGL graphic context
    ... PARENT: My child's PID is 14191 ... I'm now waiting for my child to exit... ... void display(void) ...
    (comp.soft-sys.matlab)
  • Re: vfork causes coredump
    ... pid_t pid; ... main (void) ... The child process created by vfork uses the address space of its ... the parent segfaults when trying to return ...
    (comp.unix.programmer)
  • Re: pipe question. re-post from comp.unix.programmer.
    ... they have a the following function to help sychronize the parent and ... child. ... What's the point of using pid if the function TELL_PARENTdoesn't ...
    (comp.programming)
  • [PATCH 7/28] UML - Factor out register saving and restoring
    ... * Licensed under the GPL ... +extern void init_registers(int pid); ... int is_skas_winch ...
    (Linux-Kernel)
  • Re: large files: when ubiquitous?
    ... trying to suggest that one should first of all store a pid in a malloced ... bit of memory, then pass its address into the database as a key, then ... Either answer the reasoning or shut up ... that &pid does not coincide with a void** because ...
    (comp.os.linux.development.system)