![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| High Level Programming Post questions about C, C++, Java, SQL, and other programming languages here. |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| background process | vinod.thayil | Shell Programming and Scripting | 1 | 08-17-2007 02:56 AM |
| background process | jerardfjay | Shell Programming and Scripting | 1 | 09-07-2005 08:03 AM |
| process in background | agoyal | Shell Programming and Scripting | 1 | 07-22-2004 04:56 AM |
| cause a process to be in background | avnerht | Shell Programming and Scripting | 0 | 06-22-2004 06:29 AM |
| capture the process id when starting a background process | jleavitt | Shell Programming and Scripting | 10 | 04-04-2002 05:04 AM |
|
|
Submit Tools | LinkBack | Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
using popen with background process
hi,
how to work with a background process without a controlling terminal to make use of popen or system call ? when ever i use popen or system function call in foreground process, there is no problem with respect to that .. but when the same program is run as a background process without a controlling terminal .. am receiving SIGSEGV to the program, when i traced the program using truss the program is receiving ENOTTY... pt to be noted is just as a background process with a controlling terminal there is no problem, only as a background process without any controlling terminal to it causes the problem i just want to find whether a process is running or not with the above scenario.. could somebody show me the right pointer to proceed with ? thanks a lot in advance |
| Forum Sponsor | ||
|
|
|
#2
|
|||
|
|||
|
I'm confused. Are you trying to call popen() against an already existing process?
Or is the process being created becoming a background process with no controlling terminal? In either case popen will not work. As you know. You can test to see if popen is still working with a valid stream. popen returns a FILE *ptr, so you can call (on Linux) isastream(fileno(ptr)) or more generally ioctl(fileno(ptr), I_CANPUT,0). These will return errors approiately. Assuming I understand what you're asking... You may also want to check out the isatty() function. |
|
#3
|
|||
|
|||
|
Quote:
dedicated server program which is a background process without any controlling terminal which forks another server instance to handle client requests... in that the program handling a client request - it checks whether a particular process is running or not.. the command string is framed it and it is passed to the popen function call and it fails there... |
|
#4
|
|||
|
|||
|
You actually should be using sockets or pipes. popen will fail as you see. fork does not create any stream which was not already there. If there were no tty streams to start with, forking will not create new ones for you unless you deliberately open them in the new process. You will have to use another IPC mechanism. popen requires tty streams.
By creating your own pipes you will be doing exactly what popen does, except that popen connects one pipe via stdout or stdin. |
|
#5
|
|||
|
|||
|
jim,
thanks for the reply.. i can very well understand that forking will not create new streams... to check out whether process is running or not .. i tried out a simple code Code:
# include<stdio.h>
int main()
{
char ps[100];
char bin[100]="/users/mad/net/small";
sprintf(ps, "sh -c /usr/bin/ps -fu %s | /usr/bin/grep '%s' | /usr/bin/grep -cv 'grep' > two.tmp", getlogin(), bin);
system(ps);
system("sh -c \"compress ftplog.log\"");
return 0;
}
ran this as background and without any controlling terminal - none of the operation specified in system command is working.. where am i making the mistake ? |
|
#6
|
|||
|
|||
|
I can't try this, but you need stdin, stdout, stderr for that command line to work.
The only thing I can think of is to force creation of a new process with default streams to login on the same box. rexec, ssh, maybe telnet. I don't know how to set up localhost authentication for ssh or remsh, but assuming it can be done try: Code:
sprintf(ps, "remsh localhost - l %s /usr/bin/ps -fu %s | /usr/bin/grep '%s' | /usr/bin/grep -cv 'grep' > two.tmp", getlogin(), getlogin(), bin); |
|
#7
|
|||
|
|||
|
jim, thanking u once again for the reply...
and the truth really is .. i cannot corelate what you are trying to explain... to identify whether process is running or not why it should be complicated, a process on running on box A, to identify whether a process B running on the same box A.. why it should force a new process to be created and find out whether process is running or not ... and i suspect the trap to be in this point .. (coloured one) /usr/bin/ps -fu %s | /usr/bin/grep '%s' | /usr/bin/grep -cv 'grep' > two.tmp when the redirection operator is used by a process without controlling terminal running in background, it expects a valid tty and hence throwing out ENOTTY.. could that be the problem underlying? |
|||
| Google The UNIX and Linux Forums |