sigaction and waitpid causes "interrupted system call" when calling fgets()
- From: popcornnnn@xxxxxxxxx
- Date: Sat, 26 Jan 2008 12:00:28 -0800 (PST)
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;
}
------------------------------------------------------------
.
- Follow-Ups:
- Re: sigaction and waitpid causes "interrupted system call" when calling fgets()
- From: Martin Vuille
- Re: sigaction and waitpid causes "interrupted system call" when calling fgets()
- Prev by Date: Concurrent processes and I/O multiplexing
- Next by Date: Re: sigaction and waitpid causes "interrupted system call" when calling fgets()
- Previous by thread: Concurrent processes and I/O multiplexing
- Next by thread: Re: sigaction and waitpid causes "interrupted system call" when calling fgets()
- Index(es):
Relevant Pages
|