Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932311Ab1BWNzR (ORCPT ); Wed, 23 Feb 2011 08:55:17 -0500 Received: from mail.aknet.ru ([78.158.192.28]:55657 "EHLO mail.aknet.ru" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755625Ab1BWNzM (ORCPT ); Wed, 23 Feb 2011 08:55:12 -0500 Message-ID: <4D6510A3.90905@aknet.ru> Date: Wed, 23 Feb 2011 16:50:27 +0300 From: Stas Sergeev User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.13) Gecko/20101209 Fedora/3.1.7-0.35.b3pre.fc14 Thunderbird/3.1.7 MIME-Version: 1.0 To: Linux kernel CC: Oleg Nesterov Subject: [path][rfc] add PR_DETACH prctl command Content-Type: multipart/mixed; boundary="------------010908090001040602030908" Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 8548 Lines: 137 This is a multi-part message in MIME format. --------------010908090001040602030908 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Hi. The attched patch adds the PR_DETACH prctl command. It is needed for those rare but unfortunate cases, where you can't daemonize your process before creating a thread. The effect of this command is similar to the fork() and then exit() on parent, except that: 1. PID does not change 2. Threads are not destroyed It would be nice to know what people think about such an approach. Signed-off-by: stsp@aknet.ru CC: Oleg Nesterov --------------010908090001040602030908 Content-Type: text/plain; name="pr_detach.diff" Content-Transfer-Encoding: base64 Content-Disposition: attachment; filename="pr_detach.diff" ZGlmZiAtLWdpdCBhL2ZzL3Byb2MvYXJyYXkuYyBiL2ZzL3Byb2MvYXJyYXkuYwppbmRleCA3 Yzk5YzFjLi5jY2NjZmE4IDEwMDY0NAotLS0gYS9mcy9wcm9jL2FycmF5LmMKKysrIGIvZnMv cHJvYy9hcnJheS5jCkBAIC00NjIsNyArNDYyLDcgQEAgc3RhdGljIGludCBkb190YXNrX3N0 YXQoc3RydWN0IHN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vciA9IFBSX01DRV9LSUxMX0RFRkFVTFQ7CiAJCQli cmVhazsKKwkJY2FzZSBQUl9ERVRBQ0g6CisJCQllcnJvciA9IC1FUEVSTTsKKwkJCS8qIGlm IHBhcmVudCBpcyBpbml0LCBvciBub3QgYSBncm91cCBsZWFkZXIgLSBiYWlsICovCisJCQlp ZiAobWUtPnJlYWxfcGFyZW50ID09IGluaXRfcGlkX25zLmNoaWxkX3JlYXBlcikKKwkJCQli cmVhazsKKwkJCWlmIChtZS0+Z3JvdXBfbGVhZGVyICE9IG1lKQorCQkJCWJyZWFrOworCQkJ aWYgKGFyZzIgJiB+MHhmZikKKwkJCQlicmVhazsKKwkJCXdyaXRlX2xvY2tfaXJxKCZ0YXNr bGlzdF9sb2NrKTsKKwkJCW1lLT5leGl0X2NvZGUgPSBhcmcyIDw8IDg7CisJCQltZS0+Zmxh Z3MgfD0gUEZfREVUQUNIOworCQkJZG9fbm90aWZ5X3BhcmVudChtZSwgbWUtPmV4aXRfc2ln bmFsKTsKKwkJCXdyaXRlX3VubG9ja19pcnEoJnRhc2tsaXN0X2xvY2spOworCQkJZXJyb3Ig PSAwOworCQkJYnJlYWs7CiAJCWRlZmF1bHQ6CiAJCQllcnJvciA9IC1FSU5WQUw7CiAJCQli cmVhazsK --------------010908090001040602030908-- -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/