* [RFC] set the thread name
@ 2009-06-16 18:39 Stefani Seibold
2009-06-16 19:14 ` Bert Wesarg
0 siblings, 1 reply; 5+ messages in thread
From: Stefani Seibold @ 2009-06-16 18:39 UTC (permalink / raw)
To: linux-kernel, linux-mm, Andrew Morton
Currently it is not easy to identify a thread in linux, because there is
no thread name like in some other OS.
If there were are thread name then we could extend a kernel segv message
and the /proc/<pid>/task/<tid>/... entries by a TName value like this:
cat /proc/492/task/495/status
Name: test
TName: RX-Data <- this is the thread identification field
State: S (sleeping)
Tgid: 492
Pid: 495
PPid: 1
.
.
.
This will it make much easier to determinate which thread id is
associated to a logical thread.
It would be possible do this without add a new entry to the task_struct.
Just use the comm entry which is available, because it has the same
value as the group_leader->comm entry.
The only thing to do is to replace all task_struct->comm access by
task_struct->group_leader->comm to have the old behavior. This can be
eventually encapsulated by a macro.
The task_struct->comm of a non group_leader would be than the name of
the thread.
The only drawback is that there are a lot of files which must be
modified. A quick
find linux-2.6.30 -type f | xargs grep -l -e "->comm\>" | wc -l
shows 215 files. But this can be handled.
So i propose a new system call to give a thread a name.
What do you think?
Greetings,
Stefani
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [RFC] set the thread name
2009-06-16 18:39 [RFC] set the thread name Stefani Seibold
@ 2009-06-16 19:14 ` Bert Wesarg
2009-06-16 19:40 ` Stefani Seibold
` (2 more replies)
0 siblings, 3 replies; 5+ messages in thread
From: Bert Wesarg @ 2009-06-16 19:14 UTC (permalink / raw)
To: Stefani Seibold; +Cc: linux-kernel, linux-mm, Andrew Morton
Hi,
On Tue, Jun 16, 2009 at 20:39, Stefani Seibold<stefani@seibold.net> wrote:
> Currently it is not easy to identify a thread in linux, because there is
> no thread name like in some other OS.
>
> If there were are thread name then we could extend a kernel segv message
> and the /proc/<pid>/task/<tid>/... entries by a TName value like this:
prctl(PR_SET_NAME, ...) works perfectly here.
Bert
/* -*- c -*- */
#define _GNU_SOURCE
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <stdint.h>
#include <stdbool.h>
#include <math.h>
#include <pthread.h>
#include <sys/prctl.h>
void *
thread(void *arg)
{
unsigned long i = (unsigned long)arg;
char comm[16];
snprintf(comm, sizeof comm, "task %02lu", i);
prctl(PR_SET_NAME, comm, 0l, 0l, 0l);
sleep(10);
return NULL;
}
int
main(int ac, char *av[])
{
pthread_t thr;
unsigned long i, n = 10;
char comm[16];
printf("%u\n", getpid());
sleep(5);
snprintf(comm, sizeof comm, "master");
prctl(PR_SET_NAME, comm, 0l, 0l, 0l);
sleep(5);
for (i = 0; i < n; i++)
pthread_create(&thr, NULL, thread, (void *)i);
pthread_join(thr, NULL);
return 0;
}
>
> Greetings,
> Stefani
>
>
> --
> 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/
>
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [RFC] set the thread name
2009-06-16 19:14 ` Bert Wesarg
@ 2009-06-16 19:40 ` Stefani Seibold
2009-06-16 19:54 ` Stefani Seibold
2009-06-17 1:13 ` KOSAKI Motohiro
2 siblings, 0 replies; 5+ messages in thread
From: Stefani Seibold @ 2009-06-16 19:40 UTC (permalink / raw)
To: Bert Wesarg; +Cc: linux-kernel, linux-mm, Andrew Morton
Am Dienstag, den 16.06.2009, 21:14 +0200 schrieb Bert Wesarg:
> Hi,
>
> On Tue, Jun 16, 2009 at 20:39, Stefani Seibold<stefani@seibold.net> wrote:
> > Currently it is not easy to identify a thread in linux, because there is
> > no thread name like in some other OS.
> >
> > If there were are thread name then we could extend a kernel segv message
> > and the /proc/<pid>/task/<tid>/... entries by a TName value like this:
> prctl(PR_SET_NAME, ...) works perfectly here.
>
Ooops... I did not noticed that this is already implemented. Thats works
perfectly ;-)
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [RFC] set the thread name
2009-06-16 19:14 ` Bert Wesarg
2009-06-16 19:40 ` Stefani Seibold
@ 2009-06-16 19:54 ` Stefani Seibold
2009-06-17 1:13 ` KOSAKI Motohiro
2 siblings, 0 replies; 5+ messages in thread
From: Stefani Seibold @ 2009-06-16 19:54 UTC (permalink / raw)
To: Bert Wesarg; +Cc: linux-kernel, linux-mm, Andrew Morton
Am Dienstag, den 16.06.2009, 21:14 +0200 schrieb Bert Wesarg:
> Hi,
>
> On Tue, Jun 16, 2009 at 20:39, Stefani Seibold<stefani@seibold.net> wrote:
> > Currently it is not easy to identify a thread in linux, because there is
> > no thread name like in some other OS.
> >
> > If there were are thread name then we could extend a kernel segv message
> > and the /proc/<pid>/task/<tid>/... entries by a TName value like this:
> prctl(PR_SET_NAME, ...) works perfectly here.
>
I checked it now a little bit more. It is true it works, but if i do a
segv access inside a thread a get the kernel message like:
task 09[17395]: segfault at 0 ip 08048612 sp b363c370 error 6 in
a.out[8048000+1000]
So the current implementation is not exactly what i expect. I would
prefer my solution to replace every access thread_struct->comm to
task_struct->group_leader->comm to have the right behavior.
The new system call is obsolete, it is still there.
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [RFC] set the thread name
2009-06-16 19:14 ` Bert Wesarg
2009-06-16 19:40 ` Stefani Seibold
2009-06-16 19:54 ` Stefani Seibold
@ 2009-06-17 1:13 ` KOSAKI Motohiro
2 siblings, 0 replies; 5+ messages in thread
From: KOSAKI Motohiro @ 2009-06-17 1:13 UTC (permalink / raw)
To: Bert Wesarg
Cc: kosaki.motohiro, Stefani Seibold, linux-kernel, linux-mm,
Andrew Morton, linux-api
(cc to linux-api)
> Hi,
>
> On Tue, Jun 16, 2009 at 20:39, Stefani Seibold<stefani@seibold.net> wrote:
> > Currently it is not easy to identify a thread in linux, because there is
> > no thread name like in some other OS.
> >
> > If there were are thread name then we could extend a kernel segv message
> > and the /proc/<pid>/task/<tid>/... entries by a TName value like this:
> prctl(PR_SET_NAME, ...) works perfectly here.
Oops, but man page describe another thing.
PR_SET_NAME
(Since Linux 2.6.9) Set the process name for the calling process
to arg2. ^^^^^^^^^^^^
Should we change man page? or change implementation?
I bet many developer assume the implementation is right.
>
> Bert
>
> /* -*- c -*- */
>
> #define _GNU_SOURCE
> #include <unistd.h>
> #include <stdlib.h>
> #include <stdio.h>
> #include <string.h>
> #include <stdint.h>
> #include <stdbool.h>
> #include <math.h>
> #include <pthread.h>
> #include <sys/prctl.h>
>
> void *
> thread(void *arg)
> {
> unsigned long i = (unsigned long)arg;
> char comm[16];
> snprintf(comm, sizeof comm, "task %02lu", i);
> prctl(PR_SET_NAME, comm, 0l, 0l, 0l);
>
> sleep(10);
>
> return NULL;
> }
>
> int
> main(int ac, char *av[])
> {
> pthread_t thr;
> unsigned long i, n = 10;
> char comm[16];
>
> printf("%u\n", getpid());
> sleep(5);
> snprintf(comm, sizeof comm, "master");
> prctl(PR_SET_NAME, comm, 0l, 0l, 0l);
> sleep(5);
>
> for (i = 0; i < n; i++)
> pthread_create(&thr, NULL, thread, (void *)i);
>
> pthread_join(thr, NULL);
>
> return 0;
> }
>
> >
> > Greetings,
> > Stefani
> >
> >
> > --
> > 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/
> >
> --
> 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/
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2009-06-17 1:13 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-06-16 18:39 [RFC] set the thread name Stefani Seibold
2009-06-16 19:14 ` Bert Wesarg
2009-06-16 19:40 ` Stefani Seibold
2009-06-16 19:54 ` Stefani Seibold
2009-06-17 1:13 ` KOSAKI Motohiro
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox