If you want to detach some command from the terminal, just use the standard setsid-to-background-in-a-subshell approach. Adjusting christop's script,
Code:
#!/bin/sh
if [ $# -ne 1 ]; then
printf '\nUsage: %s QEMU-KVM-IMAGE\n\n' "$0" >&2
exit 1
fi
( exec </dev/null >/dev/null 2>/dev/null
setsid qemu-kvm -m 1024 "$1" -netdev user,id=user.0 -device rtl8139,netdev=user.0 & )
Because detaching severs all connections to the terminal used to execute the command (if any), this won't tell you whether the command succeeded or not.
However, qemu-kvm does provide a perfect option for this: -daemonize. It will do initialization as normal (so you should get error messages if there is a problem with the image an so on), but then daemonize (detach from the terminal). So, you really should just use
Code:
#!/bin/sh
if [ $# -ne 1 ]; then
printf '\nUsage: %s QEMU-KVM-IMAGE\n\n' "$0" >&2
exit 1
fi
exec qemu-kvm -m 1024 "$1" -netdev user,id=user.0 -device rtl8139,netdev=user.0 -daemonize
instead.