Sponsored Content
Top Forums UNIX for Advanced & Expert Users Retrieving command line arguments of a particular PID Post 302251085 by redoubtable on Saturday 25th of October 2008 05:04:06 AM
Old 10-25-2008
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:
Code:
char * foobar = "foo\0bar\0example\0";
printf ("%s\n", foobar); /* this would print foo */
printf ("%s\n", foobar+4); /* this would print bar */
/* pointer arithmetics... */

 

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

Parsing the command line arguments

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)
Discussion started by: jayakhanna
7 Replies

2. Programming

command line arguments

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)
Discussion started by: bankpro
3 Replies

3. UNIX for Dummies Questions & Answers

arguments in command line

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)
Discussion started by: rrs
6 Replies

4. UNIX for Dummies Questions & Answers

Retrieving PID from a file

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)
Discussion started by: appleforme1415
5 Replies

5. Shell Programming and Scripting

command line arguments

-------------------------------------------------------------------------------- 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)
Discussion started by: skooly5
1 Replies

6. UNIX for Dummies Questions & Answers

Command line arguments.

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)
Discussion started by: Varghese
1 Replies

7. UNIX for Dummies Questions & Answers

command line arguments

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)
Discussion started by: ikeQ
1 Replies

8. Shell Programming and Scripting

Command Line Arguments - not working

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)
Discussion started by: meursault
1 Replies

9. Shell Programming and Scripting

command line arguments

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)
Discussion started by: vins_89
2 Replies

10. UNIX for Beginners Questions & Answers

Loop with command line arguments

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)
Discussion started by: echo manolis
7 Replies
GUILT-NEW(1)							   Guilt Manual 						      GUILT-NEW(1)

NAME
guilt-new - Create a new patch SYNOPSIS
guilt-new [-f] [-s] [-e|-m message] <patchname> DESCRIPTION
Create a new patch and push it on top of the stack. An optional patch description can be supplied either interactively on via the command line. OPTIONS
-f Force patch creation if there are unrefreshed changes. These changes will get automatically imported into the new patch. -s Add a Signed-off-by with your committer identifier string to the patch message. -e Edit the patch message interactively. This option can be combined with -s to easily sign off on the patch. -m <message> The "<message>" string will used as the commit message. This option can be combined with -s to easily sign off on the patch. <patchname> Name of the patch to create. This must be a legal relative pathname string. For example, "foo", "foo/bar", and "foo/bar/foobar" are all valid. EXAMPLES
Create a new patch called foobar: $ guilt-new foobar Create a patch called foo and supply a patch description interactively: $ guilt-new -e foo Create a patch called bar with a provided patch description and sign off on the patch: $ guilt-new -s -m patch-fu bar AUTHOR
Written by Josef "Jeff" Sipek <jeffpc@josefsipek.net[1]> DOCUMENTATION
Documentation by Josef "Jeff" Sipek <jeffpc@josefsipek.net[1]> GUILT
Part of the guilt(7) suite (Generated for Guilt v0.35) NOTES
1. jeffpc@josefsipek.net mailto:jeffpc@josefsipek.net Guilt v0.35 01/20/2013 GUILT-NEW(1)
All times are GMT -4. The time now is 10:59 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy