01-03-2008
Quote:
Originally Posted by
Raj Kumar Arora
And I dont want to create a new process in a thread.
The function system() takes a string which will be parsed by the shell, this can have as many arguments as the system will permit.
Under UNIX, the only way you can run a program is by "exec" which replaces the current program image with the new program.
If you want your program to continue running you have to call fork() or vfork() to create a new process, tough, but that is UNIX.
Yes, threads and fork can be a nightmare, what exactly is the problem? If it's resource contention/locking I suggest you have a look at "pthread_atfork()".
If you need to spawn a new process from a multithreaded program you have no options other than
(a) using fork/vfork
(b) calling a a function that wraps them up
(c) use IPC to talk to another program to create the new process
10 More Discussions You Might Find Interesting
1. Programming
hi there,
i was reading about the exec() function. and if i m not wrong, exec() kills your present process and starts a new process in its place. the process id remains the same.
then it says if exec is successful the text data and stack are overlayed by new file! -
i dont get this part "only... (2 Replies)
Discussion started by: a25khan
2 Replies
2. UNIX for Advanced & Expert Users
Hi all,
I need to syncronize a Solaris client with a QNX Server, modifying the client date, I need any alternative to set the sistem date (client Solaris) but i can't use commands date -a XXX (XXX are the time in seconds) and can't use rdate and ntp.
How can I do It? :confused: (2 Replies)
Discussion started by: ulisses0205
2 Replies
3. Shell Programming and Scripting
Hi,
I wrote a smiple ksh function
send_notification() {
...
}
and want to execute it on each file, matched by the find command.
I tried:
find / -name "*.err" -mtime -8 -exec send_notification {} \;
but it doesn't work. What should I do? I work in ksh on Hp-Ux.
Regards,
Pit (11 Replies)
Discussion started by: piooooter
11 Replies
4. UNIX for Advanced & Expert Users
I would like to call a particular function in a C program using execl(). Is this possible using execl or anyother function ?
Thanks (2 Replies)
Discussion started by: vpraveen84
2 Replies
5. Programming
Runtime.getSystem.exec() waits for child process to complete .. I do not want to wait for the child process to complete ..what is the option which has to be used ? (2 Replies)
Discussion started by: shafi2all
2 Replies
6. Shell Programming and Scripting
Hi All,
I want to execute a piped command like 'ls /opt | grep xml' using array as parameters list. How can I do that? (2 Replies)
Discussion started by: bharadiaam
2 Replies
7. Shell Programming and Scripting
I am new in Perl.
I am working in simple script and the varibles are working well outside the exec or system command.
but they don't work as parameters to exec or system command.
The script is attached.
please help. (8 Replies)
Discussion started by: ahmed_zaher
8 Replies
8. UNIX for Dummies Questions & Answers
Hi Guys ,
I want to use system function in C to do the following work.
cp <file1> <file2> and then ><file1>
e,g cp \var\log\cpm_cpmd_1.log.1 \var\log\cpm_cpmd_1.log.2 and then
>\var\log\cpm_cpmd_1.log.1
1. g_config_info.cpmm_config.cpm_log_path=\var\log\
2. ... (3 Replies)
Discussion started by: meet123321
3 Replies
9. Programming
Hi again ;) Now I want to make a program that will execute the programs with exec, asking the user if he wants the program to run in background or foreground.
scanf("%c",&caracter);
if (caracter=='y'){
printf("Has decidido ejecutarlo en background\n");
if((pid=fork())==0) {// fork para... (3 Replies)
Discussion started by: lamachejo
3 Replies
10. Shell Programming and Scripting
I have the following bash script lines in a file named test.sh.
#!/bin/bash
#
# Write Date to cron.log
#
echo "Begin SSI Load $(date +%d%b%y_%T)"
#
# Get the latest rates file for processing.
#
d=$(ls -tr /rms/data/ssi | grep -v "processed" | tail -n 1)
filename=$d
export filename... (3 Replies)
Discussion started by: ginowms
3 Replies
vfork(2) System Calls Manual vfork(2)
Name
vfork - spawn new process in a virtual memory-efficient way
Syntax
pid = vfork()
int pid;
Description
The can be used to create new processes without fully copying the address space of the old process, which is inefficient in a paged envi-
ronment. It is useful when the purpose of would have been to create a new system context for an The system call differs from in that the
child borrows the parent's memory and thread of control until a call to or an exit (either by a call to or abnormally.) The parent process
is suspended while the child is using its resources.
The system call returns a value of zero (0) in the child's context and, later, the pid of the child in the parent's context.
The system call can normally be used just like It does not work, however, to return while running in the childs context from the procedure
which called because the eventual return from would then return to a nonexistent stack frame. Be careful, also, to call _exit rather than
exit if you cannot call because exit will flush and close standard I/O channels and thereby cause problems in the parent process's standard
I/O data structures. Even with it is wrong to call exit, because buffered data would then be flushed twice.
Restrictions
To avoid a possible deadlock situation, processes which are children in the middle of a are never sent SIGTTOU or SIGTTIN signals. Rather,
output or ioctls are allowed, and input attempts result in an end-of-file indication.
Diagnostics
Same as for
See Also
execve(2), fork(2), sigvec(2), wait(2)
vfork(2)