Skip to main content
more info
Source Link
user313992
user313992

You should add a proper she-bang line (#! /bin/sh or #! /bin/bash) to your script if you want it to appear with its name in the process list.

Example:

$ cat foo
sleep 10

$ ./foo &
[4] 4403
$ ps -q 4403
  PID TTY          TIME CMD
 4403 pts/3    00:00:00 bash

$ cat bar
#! /bin/sh
sleep 10

$ ./bar &
[5] 4406
$ ps -q 4406
  PID TTY          TIME CMD
 4406 pts/3    00:00:00 bar

Otherwise, on linux you can still find the name of the script from the /proc/PID/fd directory:

$ ./foo &
[2] 5125
$ ls -l /proc/5125/fd
total 0
lrwx------ 1 ahq ahq 64 Oct 22 17:57 0 -> /dev/pts/3
lrwx------ 1 ahq ahq 64 Oct 22 17:57 1 -> /dev/pts/3
lrwx------ 1 ahq ahq 64 Oct 22 17:57 2 -> /dev/pts/3
lr-x------ 1 ahq ahq 64 Oct 22 17:57 254 -> /tmp/foo
lrwx------ 1 ahq ahq 64 Oct 22 17:57 255 -> /dev/pts/3

Notice to forth line, the 254 fd which points to the path of the script being run. With other shells than bash it will be other fd, like 3 or 10.

That could also be reverse searched with lsof /tmp/foo.

You should add a proper she-bang line (#! /bin/sh or #! /bin/bash) to your script if you want it to appear with its name in the process list.

Example:

$ cat foo
sleep 10

$ ./foo &
[4] 4403
$ ps -q 4403
  PID TTY          TIME CMD
 4403 pts/3    00:00:00 bash

$ cat bar
#! /bin/sh
sleep 10

$ ./bar &
[5] 4406
$ ps -q 4406
  PID TTY          TIME CMD
 4406 pts/3    00:00:00 bar

You should add a proper she-bang line (#! /bin/sh or #! /bin/bash) to your script if you want it to appear with its name in the process list.

Example:

$ cat foo
sleep 10

$ ./foo &
[4] 4403
$ ps -q 4403
  PID TTY          TIME CMD
 4403 pts/3    00:00:00 bash

$ cat bar
#! /bin/sh
sleep 10

$ ./bar &
[5] 4406
$ ps -q 4406
  PID TTY          TIME CMD
 4406 pts/3    00:00:00 bar

Otherwise, on linux you can still find the name of the script from the /proc/PID/fd directory:

$ ./foo &
[2] 5125
$ ls -l /proc/5125/fd
total 0
lrwx------ 1 ahq ahq 64 Oct 22 17:57 0 -> /dev/pts/3
lrwx------ 1 ahq ahq 64 Oct 22 17:57 1 -> /dev/pts/3
lrwx------ 1 ahq ahq 64 Oct 22 17:57 2 -> /dev/pts/3
lr-x------ 1 ahq ahq 64 Oct 22 17:57 254 -> /tmp/foo
lrwx------ 1 ahq ahq 64 Oct 22 17:57 255 -> /dev/pts/3

Notice to forth line, the 254 fd which points to the path of the script being run. With other shells than bash it will be other fd, like 3 or 10.

That could also be reverse searched with lsof /tmp/foo.

Source Link
user313992
user313992

You should add a proper she-bang line (#! /bin/sh or #! /bin/bash) to your script if you want it to appear with its name in the process list.

Example:

$ cat foo
sleep 10

$ ./foo &
[4] 4403
$ ps -q 4403
  PID TTY          TIME CMD
 4403 pts/3    00:00:00 bash

$ cat bar
#! /bin/sh
sleep 10

$ ./bar &
[5] 4406
$ ps -q 4406
  PID TTY          TIME CMD
 4406 pts/3    00:00:00 bar