On Solaris, the command line arguments of a running process are stored at: /proc/<pid>/psinfo
On Linux, the command line arguments of a running process are stored at: /proc/<pid>/cmdline
These two files are not text files, so I'm not sure how to read the contents.
Where can I find example C code to read the contents of the "psinfo" and "cmdline" files?
In Linux, cmdline is to be used as a regular file which splits arguments by nil chars. So, if you have three arguments named 1.foo 2.bar 3.example, then cmdline will have "foo\0bar\0example\0".
Just read cmdline's content and print the arguments by indexing all \0 locations and using pointer arithmetics.
PS: remember that most C string functions stop at '\0' and if you where to have a string like:
I am able to read in the contents of the "cmdline" file into a variable,
but when I try to print out the string, the output shows only characters before
the first null character.
How do I get the other characters after the first null character.
You suggested that i use pointer arithmetic, but how do i'm not sure
how to get the index of the '\0'.
I used strtok(), but it stops processing after the first null.
my code is below.
-------------------------------------------------
% cd /proc/14007
% cat cmdline
emacs--background-colorblack/tmp/abc
% a.out /proc/14007/cmdline
file length is: 0
content is [emacs] <<<<<----- everything after first null character is not shown
strlen: 5
1: emacs
Tokenizing complete
Ubuntum, Bash version: 4.3.46
Hi,
how can I create a loop where the command line arguments change (increase) and every time the number of arguments is different ?
### I have many gene names... that mean gene1=$2, gene2=$3, ...... geneN=$N+1
### some time the number of gene is 25, other... (7 Replies)
hi,,,,
I want to create a command prompt, for example "prompt>", so my prompt need to handle commands, for example "prompt>cmd", so i want to know how to get arguments for my own commands cmd, i.e. default argc should contain arguments count and argv should point to the argument vector i.e, for... (2 Replies)
I am new to the world of Unix and shell scripting and have been trying to get the following simple script to work:
#!/bin/bash
echo "what is your age?"
echo "you are $1 years old"I want to be able to enter my age on the command line, when prompted, and it return the... (1 Reply)
hi, can someone how to accept command line arguments as a variable using in script?
like: ./scriptname arguments
by accept arguments, I can use it in my script?
thx! (1 Reply)
I am working on a script wherein i need the user to enter the Build ID
for eg:the command line will show
enter the build ID
Now on entering the build ID it should be assigned to @ARGV.
How can this be done.? (1 Reply)
--------------------------------------------------------------------------------
I have this while loop and at the end I am trying to get it to tell me the last argument I entered. And with it like this all I get is the sentence with no value for $1. Now I tried moving done after the sentence... (1 Reply)
Hello
I need to retrieve the content of a file in the shell script file(.sh file).
I store the Process ID of the a process in file.Only the PID is available in that file.
Inside the shell script i want to retireve the content(PID) and need to check for the existence of the Process.Basically... (5 Replies)
Hi all,
How many arguments can we pass while testing a prgm at command line..
I encountered an issue while passing 10 arguments.
For $10 its taking argument passed for $1 followed by 'zero'.
can we pass more than 9 arguments /Is there any other way.
Thanks,
rrs (6 Replies)
Hi
How to pass multi line text as a command line argument to a program.
(i.e)
./a.out hi this is sample 0 file1
where
hi this is sample should be stored in argv
0 in argv and so on... (3 Replies)
Is there a way to get the command line arguments.
I am using getopt(3) but if the arguments are more than one for a particular option than it just ignores the second argument. For eg
./a.out -x abc def
now abd will be got with -x using getopt "( x : )" and string abc\0def will get stored... (7 Replies)