LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 01-12-2006, 10:10 AM   #1
sachitha
Member
 
Registered: Aug 2003
Location: Sri Lanka
Distribution: Redhat 9.0
Posts: 104

Rep: Reputation: 15
problems with "ps -l", time slicing and fork()


in the heading list in ps -l, what do WCHAN, SZ, ADDR, NI, PRI, and C mean?? like the way F means for process flags...
Can someone plz explain the concept of "time slicing" with relation to the kernal scheduler??

in a program where you give 2 fork() commands, why is it important to have sleep command?? if u exclude the sleep command you get funny output..
////
main()
{
fork();
fork();
printf("parent pid %d\n", getppid());
sleep(3);
}
//////
 
Old 01-12-2006, 10:32 AM   #2
graemef
Senior Member
 
Registered: Nov 2005
Location: Hanoi
Distribution: Fedora 13, Ubuntu 10.04
Posts: 2,379

Rep: Reputation: 148Reputation: 148
man ps and page down to the description of the headings...
 
Old 01-12-2006, 10:35 AM   #3
graemef
Senior Member
 
Registered: Nov 2005
Location: Hanoi
Distribution: Fedora 13, Ubuntu 10.04
Posts: 2,379

Rep: Reputation: 148Reputation: 148
Time Slice, and follow the link to multi tasking
 
Old 01-12-2006, 10:40 AM   #4
graemef
Senior Member
 
Registered: Nov 2005
Location: Hanoi
Distribution: Fedora 13, Ubuntu 10.04
Posts: 2,379

Rep: Reputation: 148Reputation: 148
What is the funny output that you get?
 
Old 01-13-2006, 06:41 AM   #5
sachitha
Member
 
Registered: Aug 2003
Location: Sri Lanka
Distribution: Redhat 9.0
Posts: 104

Original Poster
Rep: Reputation: 15
the funny output that i get is...

the output that i get with the sleep command is
parent pid 3947
parent pid 3946
parent pid 3946
parent pid 2699

the output that i get without the sleep command is..
parent pid 3947
parent pid 3946
[XXX @localhost]parent pid 1
parent pid 1 (with the curser blinking continuously at this point)
 
Old 01-13-2006, 08:02 AM   #6
bigearsbilly
Senior Member
 
Registered: Mar 2004
Location: england
Distribution: Mint, Armbian, NetBSD, Puppy, Raspbian
Posts: 3,515

Rep: Reputation: 239Reputation: 239Reputation: 239
pid 1
is the init process.

congratulations kid, you've created a Zombie!
 
Old 01-13-2006, 08:04 AM   #7
bigearsbilly
Senior Member
 
Registered: Mar 2004
Location: england
Distribution: Mint, Armbian, NetBSD, Puppy, Raspbian
Posts: 3,515

Rep: Reputation: 239Reputation: 239Reputation: 239
as you are playing with forks;
you should become very familiar with the pkill command.
you may need it.
 
Old 01-13-2006, 08:22 AM   #8
graemef
Senior Member
 
Registered: Nov 2005
Location: Hanoi
Distribution: Fedora 13, Ubuntu 10.04
Posts: 2,379

Rep: Reputation: 148Reputation: 148
With zombie processes you want to handle them with a waitpid signal handler on the SIGCHLD signal. Which may sound like a lot of gobbledegook however it should give you sufficient information to do an effective goggle and make some sense of it .

As for your code the standard approach is to look at the return from fork. If it is zero then you are in the parent process, if it is non zero then you are in the child process and the value returned is the pid of the parent. The reason you have four values displayed is there is first of all the parent, then the parent creates a child (1st fork) then the 1st child and the parent create a child each (2nd fork), giving you a total of four children. If you check that you are in the parent process before forking then you will create a total of two children and one parent.

I hope that helps,

graeme.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Where to download precompiled bash binaries, such as "time" and "top"? elinuxqs Linux - Newbie 12 11-14-2005 08:36 PM
Lost DHCP Lease when putting computer in "Standby" mode for a "long" time pnellesen Linux - Networking 1 01-06-2005 11:44 PM
why iam getting problems like "...too many files opened" or "segmentation fault" naren_0101bits Linux - Newbie 2 07-19-2004 12:20 PM
I admit to lazyness: Can I "fork" a stream of data (dual use)? JZL240I-U Linux - General 7 11-13-2003 02:17 AM
anging "Protocol" option to "IMPS/2" in XF86Config-4 causes problems zstingx Linux - General 2 10-27-2003 09:47 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 03:06 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration