File: prctl_demo.c

package info (click to toggle)
python-setproctitle 1.3.6-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 276 kB
  • sloc: ansic: 946; python: 658; makefile: 21
file content (29 lines) | stat: -rw-r--r-- 821 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
/* A test to check what happens using ``prctl()``.
 *
 * The ``prctl()`` call is available in Linux from 2.6.9.
 *
 * See http://www.kernel.org/doc/man-pages/online/pages/man2/prctl.2.html
 */

#include <sys/prctl.h>          /* for prctl() */
#include <linux/prctl.h>        /* for PR_SET_NAME */

#include <stdio.h>
#include <unistd.h>

int
main(int argc, char **argv)
{
    printf("Process PID: %i\n", getpid());

    prctl(PR_SET_NAME, "Hello world");
    printf("Title changed, press enter\n");
    getchar();

    /* The string set by prctl can be read in ``/proc/PID/stat``
     * and ``/proc/PID/status``. It is displayed by ``ps`` but not by ``ps a``
     * (which instead displays the content of ``/proc/PID/cmdline``). ``top``
     * toggles between both visualizations pressing ``c``.
     */
    return 0;
}