Collin Anderson
Collin Anderson

Reputation: 15444

is there a way to put comments in a unix command line?

I'm writing a program (in python) that calls a separate program (via subprocess). I'm finding that in some cases the sub program is getting stuck running. I can see the sub-program by running top, and if i press "c", I can see the full command line.

What I want, is to be able to stick debugging data (like current thread id, etc) in the command line when i'm calling the sub program, so I can futher debug my problem.

Is there a way to put comments in command line arguments such that they show up in top?

Upvotes: 2

Views: 910

Answers (2)

William Pursell
William Pursell

Reputation: 212248

Instead of making them comments, put them in the environment. For example, if you have a /proc file system, you could do:

FOO=value cmd

When top shows the pid of the command, do:

tr '\000' '\012' < /proc/pid/environ | grep FOO

to see the value of FOO in the environment of the cmd. If the values contain newlines, you will need to be more careful about the display, something like:

perl -n0E 'say if /FOO/' /proc/pid/environ

Upvotes: 0

Noufal Ibrahim
Noufal Ibrahim

Reputation: 72755

I can't think of a direct way but you could write a little shell script to which you pass the actual command to run plus argument and debugging information. It would show up in the top/ps output.

Upvotes: 1

Related Questions