urgent advice needed - gcc


 
Thread Tools Search this Thread
Top Forums Programming urgent advice needed - gcc
# 1  
Old 09-19-2008
urgent advice needed - self replication

what does the statement :

static char a[100] = "a";

store in the executable image. ??

I need to make a command line parameter exist AFTER the program finishes execution.. so that when i run the code next time ( without recompiling ).. i can work with the paramter..

for example:

$./prog pipe
>hello

$./prog tyre
>pipe

$./prog foo
>pipe


Also, i dont want to store it in another file.. maybe i could write a copy of prog in memory..

I hope u got what i wanna do ..

basically how to make

int main()
{ static char a[100[]="hello";
printf("%s",a);
}

to print pipe instead of hello... i think thats what static does.. but does it remember values even when prog execution ends.. i doubt that Smilie

Last edited by a.k.aFireknight; 09-20-2008 at 06:25 PM.. Reason: apt title
# 2  
Old 09-20-2008
static essentially means the data is stored in heap memory, and that the variable cannot be seen outside the code - file scope it is called.

You want data to persist from one invocation of a compiled file to the next? Right?
Well when your code exits, all of the memory is reclaimed by the system. Your data is lost. The only ways to do this:
1. have a process running all the time - itt stores the data in an environment variable
2. store the data in a file
3. Enter the value as a parameter when the process starts.
# 3  
Old 09-20-2008
static essentially means the data is stored in heap memory, and that the variable cannot be seen outside the code - file scope it is called.

You want data to persist from one invocation of a compiled file to the next? Right?
Well when your code exits, all of the memory is reclaimed by the system. Your data is lost. The only ways to do this:
1. have a process running all the time - itt stores the data in an environment variable
2. store the data in a file
3. Enter the value as a parameter when the process starts.

Then i guess the options are to either to create another process using fork/exec or... maybe use system(..) and create a replicated program.

In any ways... your suggestion is right.. but i was wondering if we were not to use files... is their anyway to get the data back from the "executable image" using any command or code?

This is because when we make a static char * variable... does it not retain the data in the executable image from one execution to the next.

I solved the prob using files.. but files = disk ... i want to retrieve from the RAM> if there is someway to do that ?
# 4  
Old 09-21-2008
Quote:
Originally Posted by a.k.aFireknight

I solved the prob using files.. but files = disk ... i want to retrieve from the RAM> if there is someway to do that ?
Then create a ramdisk, mount it somewhere and use the code you've created for solving the problem using files.
# 5  
Old 09-21-2008
Why don't you set an environmet variable from you program?
# 6  
Old 09-21-2008
Hey Roman.. i am not sure environment variables are carried over from one execution of the program to the next IF they are running on two DIFFERENT shells...

I am using system() to call the the copy program from the original.. and i think system calls that in a different shell. i thought of environ earlier.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Solaris

Solaris Study Advice Needed

I just have a question regarding learning Solaris, I have a Linux and AIX background and I would like to learn Solaris, I have been giving some Solaris 10 Study Guides and just wondered how relevant they would be to Solaris 11 or should I try and get some study materials which are targeted towards... (1 Reply)
Discussion started by: markmorris182mx
1 Replies

2. UNIX for Advanced & Expert Users

Expertise advice required <<URGENT>>

:eek:i hav a shell script in my linux server, i want to execute it everyday once automatically without using cron tabs as i dont hav permission to create one. So wht sld i do??:confused: (1 Reply)
Discussion started by: Jay Thakkar
1 Replies

3. Linux

Scripting advice needed

Evening all, Im trying to get a script that will: Select the most 3 recent files in a specific directory Run a command on them (like chmod) Ask of you would like to continue Copy the files to another directory If a linux guru could help me out, it would be very much appreciated. Thanks... (2 Replies)
Discussion started by: Wiggins
2 Replies

4. UNIX for Advanced & Expert Users

'for' loop advice needed....!!

Scenario: Command used to capture IPs on a host: /usr/sbin/ifconfig -a | grep "inet" | egrep -v "inet6|0.0.0.0|192.168.100.2" | awk '{print $2}' Following for loop used to capture interface names: for INTERFACE in `/usr/sbin/ifconfig -a | nawk '$1 ~ /:$/ && $1 {sub(":$", "", $1); print... (3 Replies)
Discussion started by: ak835
3 Replies

5. Shell Programming and Scripting

Advice needed on using Script with NOHUP

All, I would like to know my below requirement can be achieved in any way in Shell Scripting? I will make this requirement of mine as understandable as I can. Requirement: I wrote a script 'my.script' which gets user-input tablenames and puts the same into an array. Also I get other inputs... (6 Replies)
Discussion started by: bharath.gct
6 Replies

6. Shell Programming and Scripting

'for' loop advice needed ....!!

/usr/sbin/ifconfig -a | grep "inet" | grep -v "inet6" | grep -v "127.0.0.1" | grep -v "0.0.0.0"|grep -v "192.168.100.2" | awk '{print $2}' I use above command to get IP addresses on AIX boxes.Values coming here are set to a variable "Host IPs.IP Addresses" in my fingerprinting engine. ... (4 Replies)
Discussion started by: ak835
4 Replies

7. UNIX for Dummies Questions & Answers

Want URGENT Advice:Career as UNIX Systme Administrator

Dear All, I have finished my MS in chemical engineering from US university and presetly on OPT work permit. I do not have software background. I have received call from consultant company. They are offering me AIX UNIX training for four weeks and find me a job. My question is how difficuilt... (5 Replies)
Discussion started by: saarth_desh
5 Replies

8. Cybersecurity

Want Urgent career Advice

Dear All, I have finished my MS in chemical engineering from US university and presetly on OPT work permit. I do not have software background. I have received call from consultant company. They are offering me AIX UNIX training for four weeks and find me a job. My question is how difficuilt... (0 Replies)
Discussion started by: saarth_desh
0 Replies

9. Solaris

Using San storage - advice needed

Thinking of using our San for network backups.. Have a Netra 240 being installed and planning to get some space on our San. Do you know what software is used to access the San from my server or what I would need to do? I know how to connect to local storage, disk arrays etc but not sure what... (1 Reply)
Discussion started by: frustrated1
1 Replies

10. Linux

programming advice needed....

i'm a grad student taking a UNIX course and a networks course (i have a background in C++ and JAVA). i'm trying to combine the two classes. My questions stems from a networks programming homework assignment below: "Using the operating system and language of your choice, develop a program to... (5 Replies)
Discussion started by: trostycp
5 Replies
Login or Register to Ask a Question