[Adium-devl] Let's abandon disk images
Graham Booker
adium at cod3r.com
Sun Apr 1 00:02:08 UTC 2007
On Mar 31, 2007, at 6:29 PM, Peter Hosey wrote:
> On Mar 31, 2007, at 14:38:37, Ofri Wolfus wrote:
>> 2. fork/exec.
>
> There are two problems with this:
> 1. If the child process (ostensibly `diskutil eject` or something)
> tries to do the eject before its parent has exited, the parent's
> executable file and probably various resources are still in use, so
> the eject will fail.
> 2. Whenever the parent process exits, it will take the child
> process with it.
>
> Problem 2 can be solved by using ptrace to detach from the child (I
> think—I've never tried). Alternatively, using signal(2) to block
> SIGHUP may work.
>
Nope, not a problem. Example file:
#include <sys/types.h>
#include <unistd.h>
extern char **environ;
int main(int argc, char *argv[])
{
char *args[] = {"/bin/sh", "-c", "sleep 5; sleep 5; sleep 5", NULL};
int forkVal = fork();
if(forkVal == 0)
execve("/bin/sh", args, environ);
}
Watch top (with no args). You will see sleep show up with three
different proccess ID's 5 seconds apart. Exactly what we want.
Note, the original a.out exited during this process. Exactly what we
wanted.
> Problem 1 can be solved by using a shell script, which you could
> pass to exec:
>
> static const char eject_argv[][] = {
> "bash", "-c",
> /*Something like the script Graham suggested*/,
> NULL
> };
> pid_t pid = execvp("bash", eject_argv);
>
> ___________________________________
> \ Peter Hosey / boredzo at adiumx.com
> PGP public key ID: C6550423 (since 2007-01-01)
:), yep, what I do here. :P
- Graham
More information about the devel
mailing list