Using system call in c [duplicate] - c

This question already has answers here:
replace system() with non-blocking function
(5 answers)
Closed 8 years ago.
Please tell me how to open two files simultaneouly using system();
I want to open two file
and I am doing it like
system("C:\temp\file1.doc");
system("C:\temp\file2.doc");
But here till the file 1 is open file 2 is not opening as the control is not able to reach the second system call , Is there a way to do open them simultaneously.
Thanks
Shashank

I would suggest two ways.
Run two threads. Call system() from each thread.
Create a child process using fork() and run system() from both parent and child processes.

Related

How to find out witch thead using specific file descriptor with C [duplicate]

This question already has answers here:
How to view thread id of a process which has opened a socket connection?
(2 answers)
Closed 3 years ago.
I have a process with 100 threads.
I know that only one thread is using a specific fd.
For example, this fd is a socket descriptor, and only one thread is using this socket with send() and receive().
How can I find out, with C, on Linux, the ID of this thread?
Is there a smarter way than attaching to each thread with ptrace and waiting until one of them will be detected?
File descriptors are part of the process. And since a file descriptor is just a nonnegative integer, and can be used by all threads of the same processes without explicit rebinding, asking "which thread holds an fd" is not a question applicable to the Linux process/threading model.
If you really want an answer then it would be: All the threads do!

Can a file descriptor be shared between unrelated processes? [duplicate]

This question already has answers here:
Portable way to pass file descriptor between different processes
(2 answers)
Closed 9 years ago.
The answer to this question shows how to share a file descriptor between two processes. I am unclear on whether this is possible with any process or only related processes. For example, is it possible to open an unnamed pipe and pass the read or write file descriptor to another unrelated process on a unix system?
Yes, you can pass a file descriptor to any other process. The only requirement is that you open a Unix domain socket to communicate between the two processes.

Find number of threads spawned by a process in Linux [duplicate]

This question already has answers here:
POSIX API call to list all the pthreads running in a process
(3 answers)
Closed 9 years ago.
I want to write a c function , which when called by the process returns number of threads created by that process.
I want to get the value not by counting but from the kernel structure ?
Which structure has this information ?
You can get a lot of information about your process by looking in /proc/$$ where $$ is your process ID.The number of threads is available atomically through /proc/$$/status.
My solution: You need write a function to analyse the file /proc/$$/status to get the number of threads.

Program based on pipe for interprocess communication [duplicate]

This question already has answers here:
Interprocess communication using pipe in Linux
(2 answers)
Program based on pipe in Linux
(2 answers)
Closed 8 years ago.
Does any one know how to write a number to pipe for that first of all i have to open the pipe, and then write suitable number to it.
Also,after writing also i have to read the number and print it.
I have tried to open the pipe with 'popen' command but i am uncertain what to give as the 1st argument to popen i.e:-
popen(const char *command, const char *type)
i want to ask what command should i give here if i want to write a number to pipe..??
you should use fd=open(FIFO_NAME,O_RDONLY); for reading fifo file.
mkfifo(FIFO_NAME,S_IFIFO|S_IRWXU|S_IRWXG|S_IRWXO);
fd=open(FIFO_NAME,O_WRONLY);
fifo is also called pipe.Here mkfifo create a fifo file and the write into a file.
Note:- that to read or write into fifo there should be a reader and writer process, Else it would be blocking one of the process.
if you don't want to write a process for reading the use cat command and writing process to see the fifo file content.

How is system() function of stdlib.h file implemented in linux? [duplicate]

This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
How does system() exactly work in linux?
For the sake of my curiosity,
I want to know that how does system() function spawn the process and its internal implemenation ?
Is is using fork , exec internally ?
On my Debian box it uses clone() that itself calls sys_clone(). You can use strace to look at system calls.

Resources