[Prev][Next][Index][Thread]
Re: fork & exec.
Asaf Sabag wrote:
>
> Hi all,
>
> How can I know if the command in the exec function was Ok?
>
> I want to backup a file by tar to /dev/fd0 by exec,
> If there is no disk in the drive I get no error from the exec because the exec passed OK,
> but on the xterm I get cannot open /dev/fd0 : no such device or address, which means that tar
> failed.
>
> The exec return -1 on error, but there is no error because the tar was found, but the tar
> failed.
If you reach the line after exec(2) then it failed. If it
succeeds then the text of the process is overwriten by the new
image and nothing of the "old" text can be executed.
So code the uses exec(2) looks like:
exec (....path and args here....);
perror ("exec failed");
exit (1);
>
> How can I know that the tar failed?
You usually wait(2) for it in the parent process.
>
> int id;
> int ExecId
Read W. Richard Stevens excellent "Advanced Programming in the UNIX
environment", a must for anyone who's lucky enough to program under
UNIX
Cheers,
--Amos
--Amos Shapira | "Of course Australia was marked for
133 Shlomo Ben-Yosef st. | glory, for its people had been
chosen
Jerusalem 93 805 | by the finest judges in England."
ISRAEL amos@dsi.co.il | -- Anonymous
Follow-Ups:
References: