You can use the ps
command, and specify the pid to examine with the -p
switch, using the -f
switch to give a full listing, or -l
for a more detailed long listing.
As an example for output:
$ sleep 60 &
[1] 31441
$ ps -lp 31441
F S UID PID PPID C PRI NI ADDR SZ WCHAN TTY TIME CMD
0 S 0 31441 31319 0 80 0 - 1423 hrtime pts/3 00:00:00 sleep
$ ps -fp 31441
UID PID PPID C STIME TTY TIME CMD
root 31441 31319 0 10:44 pts/3 00:00:00 sleep 60
This does however output a header line, which you may not want in your log file. You can trim this by using the -h
option, if your pid was 1234:
ps -lhp 1234 >> /var/log/myapp/myapp.log 2>&1
Note that I've redirected the output using >>
to append to your logfile.