LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 10-20-2004, 06:03 PM   #1
ghoughto
LQ Newbie
 
Registered: Oct 2004
Posts: 8

Rep: Reputation: 0
Question about argv[]


I am currently working on a c/c++ program that uses several child proccess (forks). The issue is I would like to see these listed by ps by the name, not by the parent name.

It was suggested that I overwrite argv[0] on the child. While this looks like it can work (tested a little) I just have a couple questions before I feel that this is safe coding.

1. Storage. How is argv stored (structure). I suspect there is a char* and a int for length. When I tested the code it looked like 'ps' still dumped the full length of the origional argv[0].

2. Is this a 'good thing' to do ? If there are any violations by messing with this please let me know, and why if you can.

Many Thanks.

example ps:

UID PID PPID C STIME TTY TIME CMD
mrx 28207 28186 0 18:44 pts/0 00:00:00 xterm
mrx 28226 28209 0 18:44 pts/1 00:00:00 ./bridgekeeper
mrx 28228 28226 0 18:44 pts/1 00:00:00 bk_thread er
mrx 28229 28186 0 18:44 pts/0 00:00:00 ps -af

(please note the extra "er" at end of test
 
Old 10-21-2004, 11:25 PM   #2
gr33ndata
Member
 
Registered: Aug 2003
Location: DMZ
Distribution: Ubuntu
Posts: 144

Rep: Reputation: 15
Argv is a char** not char*
 
Old 10-22-2004, 05:43 AM   #3
ghoughto
LQ Newbie
 
Registered: Oct 2004
Posts: 8

Original Poster
Rep: Reputation: 0
I understand argv itself but ultimately there is some underlying storage area for the actual data. If I try to redirect the pointer to where I want I am not sure of the repercussions.
 
Old 10-22-2004, 07:05 AM   #4
yuray
Member
 
Registered: Apr 2003
Location: Russia, Khotkovo
Distribution: Debian
Posts: 146

Rep: Reputation: 15
Try this
http://www.ussg.iu.edu/hypermail/lin...01.1/2281.html
 
Old 10-22-2004, 07:23 AM   #5
GtkUser
Member
 
Registered: Sep 2002
Location: Canada
Distribution: Redhat 9.0
Posts: 637

Rep: Reputation: 30
int main ( int argc, char *argv[] ) {
}

argv is an "array" of "pointers to int type".

You can use argv[row][column].
 
Old 10-22-2004, 08:23 AM   #6
ghoughto
LQ Newbie
 
Registered: Oct 2004
Posts: 8

Original Poster
Rep: Reputation: 0
Thanks to all !.

Glen
 
Old 10-25-2004, 09:38 AM   #7
shantha
LQ Newbie
 
Registered: May 2004
Location: Bangalore
Posts: 7

Rep: Reputation: 0
argv is an array of pointers to char type
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
argv[1]++ operation and sort sachitha Programming 2 10-14-2005 11:16 AM
argv[] help wanted. (In C) vexer Programming 9 11-17-2003 05:09 AM
argc argv linuxanswer Programming 8 10-25-2003 07:54 PM
Help with argv pilot1 Programming 7 08-23-2003 02:20 PM
'delete[] argv': is this correct?? Disruptor Programming 4 07-10-2003 11:06 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 03:18 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration