C program to make an exact copy of the current process in Ubundu


 
Thread Tools Search this Thread
Top Forums Programming C program to make an exact copy of the current process in Ubundu
# 1  
Old 05-01-2010
C program to make an exact copy of the current process in Ubundu

Hi All,

I am new to Linux and i need your for a program which makes the exact copy of the running process. I have got some codes but it only works for the first command and will not work for subsequent commands. Means it works for "ps" but will not work for "ps u". I have changed the code to accept the whole string but still the output for two word commands are not appearing. Hope some one can give me a help. My codes are below.

Code:
int main()
{
char command[80];
while (putchar('@'), gets(command)) {
if (fork())
wait(0); /* Parent */
else { /* Child */
execlp(command, command, 0);
printf("command not found\n");
exit(1);
}
}
}


Last edited by radoulov; 05-01-2010 at 07:21 PM.. Reason: Code tags, please!
# 2  
Old 05-02-2010
First off -
execlp (or any exec call) clobbers the "original" process memory - it creates a brand new one. The old copy is gone for ever.

Next you have to pass the exec call a file with separated arguments
maybe something like execve "/bin/ksh", "-c", "usr/bin/grep 'hi' /path/to/somefile"
You are using a single command variable, it has to be parsed into the proper chunks.

fork() creates an exact copy, not exec.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to find the exact process using ps aux command?

Please do not post a technical question in the @How to contact....' forum. I have moved this for you. Hello Everyone, Please help me on this, Requirement here is to check whether the process is running using the process id. For the below scenario, I m trying to grep 1750 process id to... (3 Replies)
Discussion started by: Hari A
3 Replies

2. Shell Programming and Scripting

Command to get exact tomcat process I am running ignoring other java process

Team, I have multiple batchjobs running in VM, if I do ps -ef |grep java or tomcat I am getting multiple process list. How do I get my exact tomcat process running and that is unique? via shell script? (4 Replies)
Discussion started by: Ghanshyam Ratho
4 Replies

3. Solaris

How to make an exact image copy of a SCSI hard drive in Solaris 8 OS?

To Solaris 8 Experts, Please let me know what's the best method / procedure as well as the Solaris 8 commands for accomplishing the following tasks on a production Sun Enterprise 250 Server running Sun Solaris 8 Operating System: 1. Make an exact image/copy of the SCSI Hard Drive in the... (3 Replies)
Discussion started by: ssabet
3 Replies

4. Shell Programming and Scripting

Make background process interact with fg process

Hi, I have written a menu driven shell script in which as per the choice, I run the another script on background. For eg: 1. get info 2)process info 3)modify info All the operations have different scripts which i schedule in background using &. However I wish to display the error... (0 Replies)
Discussion started by: ashima jain
0 Replies

5. Shell Programming and Scripting

Grep the exact process in perl script

I am working on one script where I need to grep the exact process in perl script. for e.g. when I run simple grep command on the linux machine it gives me two process mGateway_mvc_q01 and mGateway_mvc_q01_v7 which is not the correct result.I tried to use ( ps -eAf | grep ^mGateway_mvc_q01$) but... (1 Reply)
Discussion started by: anuragpgtgerman
1 Replies

6. UNIX for Dummies Questions & Answers

Running different process from current process?

I have been having some trouble trying to get some code working, so I was wondering...what system calls are required to execute a different program from an already running process? (1 Reply)
Discussion started by: Midwest Product
1 Replies

7. Shell Programming and Scripting

How to make the parent process to wait for the child process

Hi All, I have two ksh script. 1st script calls the 2nd script and the second script calls an 'C' program. I want 1st script to wait until the 'C' program completes. I cant able to get the process id for the 'C' program (child process) to make the 1st script to wait for the second... (7 Replies)
Discussion started by: sennidurai
7 Replies

8. UNIX for Dummies Questions & Answers

Filtering exact process name from ps

Hi Gurus, I have two processes running on a Unix box, named say, PRCS1 and PRCS1X. I want to check whether process PRCS1 is running or not, and depending on that I have to make further decisions while writing a shell script. I am using: ps -eaf|grep PRCS1|grep -v grep But the... (2 Replies)
Discussion started by: sagarparadkar
2 Replies

9. Shell Programming and Scripting

how to start a process and make it sleep for 5 mins and then kill that process

how to start a process and make it sleep for 5 mins and then kill that process (6 Replies)
Discussion started by: shrao
6 Replies

10. UNIX for Advanced & Expert Users

how to make a current running process ignore SIGHUP signal?

I ask this question since sometimes i run a time-consuming ftp in foreground and forget to use nohup ftp.sh & to put this work background and can still running after i log off. Assume this ftp task have run 1 hour, and still 1 hour time to end, i don't want to abort the ftp, first, i use ctrl+Z... (3 Replies)
Discussion started by: stevensxiao
3 Replies
Login or Register to Ask a Question