473,387 Members | 1,463 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

creating child process

am I lame ??
sounds like i didnt grab something !!!
ive changed my code now!!
whats wrong??
y for 2 loops, it prints 3 loops?

#include <stdio.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <unistd.h>
#include <fcntl.h>

int main(){
pid_t one, two;
char A = 'A';
char B = 'B';
int i=0;

int desc = open ("aba.txt", O_CREAT | O_RDWR , 0700
);
if ( desc < 0 ) {
perror ("open");
exit(-1);
}

lseek(desc,0,sizeof(char));

one = fork();

switch ( one ) {
case 0 : for(i=0;i<2;i++){
write(desc,&A,sizeof(char));
}
exit(0);

case -1 : perror("fork");
exit(-1);

default : waitpid(one,NULL,0);
two = fork();
if ( two == 0 ) {
write(desc,&B,sizeof(char));
waitpid(two,NULL,0);
}
close(desc);
system("cat aba.txt");
exit(0);
}

}

in the end i wish to output ABABABABAB

Nov 14 '05 #1
6 1766
ch******@gmail-dot-com.no-spam.invalid (Clunixchit) writes:
[snip]
#include <stdio.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <unistd.h>
#include <fcntl.h>

[snip]

Try comp.unix.programmer.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Nov 14 '05 #2
what do you mean?

Nov 14 '05 #3
Clunixchit <ch******@gmail-dot-com.no-spam.invalid> wrote:
what do you mean?


That what you try to do there is something Unix-specific and isn't
a C problem at all (which is the topic of this group). That's why
you got told to ask in comp.unix.programmer where fork() and
friends is an often discussed topic.

Regards, Jens
--
\ Jens Thoms Toerring ___ Je***********@physik.fu-berlin.de
\__________________________ http://www.toerring.de
Nov 14 '05 #4
ch******@gmail-dot-com.no-spam.invalid (Clunixchit) wrote:
# am I lame ??
# sounds like i didnt grab something !!!
# ive changed my code now!!
# whats wrong??
# y for 2 loops, it prints 3 loops?

I never remember the rules for sharing file descriptors of disk files. You might
get a better response from comp.unix.programmer.

# case 0 : for(i=0;i<2;i++){
# write(desc,&A,sizeof(char));
# }

# default : waitpid(one,NULL,0);
# two = fork();
# if ( two == 0 ) {
# write(desc,&B,sizeof(char));
# waitpid(two,NULL,0);
# }

You're doing the wait for child two in child two. You're not doing a wait in the
parent.
--
SM Ryan http://www.rawbw.com/~wyrmwif/
This is one wacky game show.
Nov 14 '05 #5
> Anonymouswrote:
Clunixchit <ch******@gmail-dot-com.no-spam.invalid> wrote:
what do you mean?

That what you try to do there is something Unix-specific and isn't
a C problem at all (which is the topic of this group). That's why
you got told to ask in comp.unix.programmer where fork() and
friends is an often discussed topic.

Regards, Jens
--
\ Jens Thoms Toerring ___ Je***********@physik.fu-berlin.de
\__________________________
http://www.toerring.de[/quote:78737363b3]

where is comp.unix.programmer?
is it comp.unix.development?
the "notify me when a reply is posted" is not working?

Nov 14 '05 #6
ch******@gmail-dot-com.no-spam.invalid (Clunixchit) writes:
Anonymouswrote: Clunixchit <ch******@gmail-dot-com.no-spam.invalid> wrote:
what do you mean?

That what you try to do there is something Unix-specific and isn't
a C problem at all (which is the topic of this group). That's why
you got told to ask in comp.unix.programmer where fork() and
friends is an often discussed topic.

Regards, Jens
--
\ Jens Thoms Toerring ___ Je***********@physik.fu-berlin.de
\__________________________
http://www.toerring.de[/quote:78737363b3]

where is comp.unix.programmer?
is it comp.unix.development?
the "notify me when a reply is posted" is not working?


Please quote properly. The way your article was formatted makes it
appear that you wrote what Jens actually wrote, and that your
questions at the end ("where is comp.unix.programmer?") are part of
the signature. Quoted material is normally prefixed by "> ". Your
newsreader software should do this for you; if it doesn't, it's either
misconfigured or broken. The "[/quote:78737363b3]" stuff may be
specific to your system; please don't use it here.
where is comp.unix.programmer?
It's a newsgroup, like comp.lang.c. If your server doesn't carry it,
you'll need to talk to someone on your end.
is it comp.unix.development?
No, as far as I know there is no newsgroup named "comp.unix.development".
the "notify me when a reply is posted" is not working?


We can't help you with that.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Nov 14 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Markus Franz | last post by:
Hi. I created a little script: for currenturl in sys.argv: pid = os.fork() if pid == 0: signal.alarm(10) do_something() # placeholder for the download and print routine
0
by: Scott Yenor | last post by:
Hello, I am writing a control library that has a control that inherits from System.Web.UI.Control. The control works fine and I am able to loop through the child controls and display everything...
2
by: sunil | last post by:
Hi All, I am tring to debug the following program.I written this program in HP-Unix and I am using the GDB as a debugger. #include <stdio.h> #include<unistd.h> int main() { int pid; pid =...
9
by: Sakagami Hiroki | last post by:
Hi, What is the easiest way to create a daemon process in Python? Google says I should call fork() and other system calls manually, but is there no os.daemon() and the like? Regards, --...
2
by: Fred Heida | last post by:
Hi, Question on Vista Run As Administrator. If i have exe which creates a child process, using the Process class, and this exe is Run As Asministror, is there a way to have the child process...
5
by: vsowmya | last post by:
Hi I have to develop a c program to create a parent process that spawn three child process. i have written a code but that was not working out.Please help me in getting the desired output of my...
22
by: Jason Zheng | last post by:
This may be a silly question but is possible for os.wait() to lose track of child processes? I'm running Python 2.4.4 on Linux kernel 2.6.20 (i686), gcc4.1.1, and glibc-2.5. Here's what happened...
2
by: Karthik Gurusamy | last post by:
Hi, Wondering if there is a way to measure a child process's cpu usage (sys and user) when the child is still running. I see os.times() working fine in my system (Linux 2.6.9-42.7.ELsmp), but it...
1
by: sternr | last post by:
Hey, Is there a way to create a new process that will not be my child process? Meaning, that after opening the new process, if I'll open TaskManager and do "End Process Tree" on the parent...
5
by: Iain | last post by:
Hi, I have a function that only accepts filenames, rather than file-like objects (because its a wrapper around a C++ function, I think). I want to feed some potentially large "files" into this...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.